c# - Passing an object in RedirectToAction -
i have controller has received post back, , has processed user has requested. build object, , now, want redirecttoaction..
return redirecttoaction() ("index", "location", r);
where r named object working with. on target action, r null.
public actionresult index(locationbyaddressreply location)
now, read few posts on here this, battling understand.
an option put forward wasl
tempdata["myobject"] = myobject;
but seems ... strange. not type safe. suitable way pass objects?
yes can values using tempdata
on redirect. method should looks like:
public actionresult yourredirectmethod() { tempdata["myobject"]=r; return redirecttoaction() ("index", "location"); }
and
public actionresult index() { locationbyaddressreply location=null; if(tempdata["myobject"]!=null) { location=(locationbyaddressreply)tempdata["myobject"]; } }
in way values of model previousely set on redirect method.
Comments
Post a Comment