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

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -