-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;
}
Serhat Koroglu
  • 1,263
  • 4
  • 19
  • 41

1 Answers1

-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)

Rahul Pr
  • 11
  • 3