I've a class that hold all the necessary properties. I want to pass the instance of that class in RedirectToAction. Right now, I can pass the instance but the action to which it redirect, doesn't receive that same instance. The target action has new instance
of class.
eg.
AbcFilter a = new AbcFilter();
a.ABCname="abc";
RedirectToAction("AbcAction",a);
Public ActionResult AbcAction(AbcFilter a)
{// this method receives the "a" as new instance, but not the same that I pass in RedirectToAction
RedirectToAction() works by shoving data into the URL. Since an AbcFilter can't be put into the URL, this doesn't work. Try using TempData for this instead:
TempData["abc"] = the AbcFilter;
return RedirectToAction("AbcAction");
At the destination:
public ActionResult AbcAction() {
AbcFilter abc = TempData["abc"] as AbcFilter;
}
sp_412000@ya...
Member
661 Points
347 Posts
RedirectToAction and instance of class
Jan 27, 2010 06:44 PM|LINK
I've a class that hold all the necessary properties. I want to pass the instance of that class in RedirectToAction. Right now, I can pass the instance but the action to which it redirect, doesn't receive that same instance. The target action has new instance of class.
eg.
AbcFilter a = new AbcFilter();
a.ABCname="abc";
RedirectToAction("AbcAction",a);
Public ActionResult AbcAction(AbcFilter a)
{// this method receives the "a" as new instance, but not the same that I pass in RedirectToAction
}
Any idea...
levib
Star
7702 Points
1099 Posts
Microsoft
Re: RedirectToAction and instance of class
Jan 27, 2010 06:55 PM|LINK
RedirectToAction() works by shoving data into the URL. Since an AbcFilter can't be put into the URL, this doesn't work. Try using TempData for this instead:
TempData["abc"] = the AbcFilter; return RedirectToAction("AbcAction");At the destination:
public ActionResult AbcAction() { AbcFilter abc = TempData["abc"] as AbcFilter; }sp_412000@ya...
Member
661 Points
347 Posts
Re: RedirectToAction and instance of class
Jan 27, 2010 07:11 PM|LINK
Awesome... Thanks a lot
ali62b
Contributor
4750 Points
690 Posts
Re: RedirectToAction and instance of class
Jan 27, 2010 07:13 PM|LINK
Try this :
RedirectToAction("ActionName", "ControllerName", ViewData.Model = new AbcFilter() { ABCname= "abc"});
Hope this helps.
@BlueCoder
Regards