I got a view List.aspx
that is bound to the class Kindergarten
In the controller:
public ActionResult List(int Id) { Kindergarten k = (from k1 in _kindergartensRepository.Kindergartens where k1.Id == Id select k1).First(); return View(k); }
That works.
But this doesn't
[AcceptVerbs(HttpVerbs.Post)] public ActionResult Add(...) { //... Kindergarten k = ... return RedirectToAction("List", k); }
How should I redirect to the list view, passing k as the model?
Thanks!
I don't believe ModelBinding exists when using RedirectToAction. Your best options, however, is to use the TempData collection to store the object, and retrieve it in the following action.
[AcceptVerbs(HttpVerbs.Post)] public ActionResult Add(...) { //... Kindergarten k = ... TempData["KG"] = k; return RedirectToAction("List"); }
In your List Action
public ActionResult List() { Kindergarten k = (Kindergarten)TempData["KG"]; // I assume you need to do some stuff here with the object, // otherwise this action would be a waste as you can do this in the Add Action return View(k); }
Note: TempData collection only holds object for a single subsequent redirect. Once you make any redirect from Add, TempData["KG"] will be null (unless you repopulate it)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With