I am in controller A and is using redirectToRoute to get to controller B where I am passing two object parameters but I notice these values are null on redirection.RedirectToRoute does not allow the pas开发者_C百科sing of objects?????
When redirecting you can only pass simple scalar values and not complex objects. Example:
public ActionResult Index()
{
SomeModel model = ...
return RedirectToAction("Foo", new
{
Prop1 = model.Prop1,
Prop2 = model.Prop2,
Prop3 = model.Prop3,
});
}
public ActionResult Foo(SomeModel model)
{
// model.Prop1, model.Prop2 and model.Prop3 will be correctly bound here
...
}
Another possibility is to persist the object to your datastore and pass only the corresponding id:
public ActionResult Index()
{
SomeModel model = ...
string id = Repository.Save(model);
return RedirectToAction("Foo", new { id = id });
}
public ActionResult Foo(string id)
{
// fetch the model from repository:
SomeViewModel model = Repository.Load(id);
...
}
精彩评论