-2

How can I pass query string values to a view model parameter that has default values in ASP.net MVC app?

I tried so but didn't succeed;

public ActionResult Index(MyAnotherVM filter){
  // filter.p doesn't set passed value and it equals to 1
}

public class MyAnotherVM {
 public int p { get { return 1; } set { } }
 // or
 public int p=1;
}
2

1 Answer 1

-1

You can make use of TempData

[HttpPost]
public ActionResult FillStudent(Student student1)
{
    TempData["student"]= new Student();
    return RedirectToAction("GetStudent","Student");
    }

[HttpGet]
public ActionResult GetStudent(Student passedStd)
{
    Student std=(Student)TempData["student"];
    return View();
}

Approach 2:

using Query string data passed

Or you can frame it with the help of query strings like

return RedirectToAction("GetStudent","Student", new {Name="John",             Class="clsz"});

This will generate a GET Request like

Student/GetStudent?Name=John & Class=clsz

But make sure you have [HttpGet] since RedirectToAction will issue GET Request(302)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.