asp.net mvc 2
I have this action in Identity controller
public ActionResult Details(string id, MessageUi message)
{
And I’m trying to redirect to this action from another controller, but I don’t know how should I pass the message parameter
I was trying with
var id = "someidvalue"
var message = new MessageUi("somevalue");
return RedirectToAction("Details", "Identity", new { id, message});
}
but message parameter is null
That’s normal. You cannot pass complex objects in urls when redirecting and that’s the reason why the
MessageUiobject is not received. Only scalar properties which will be translated into&-separated key/value pairs in the url.One possibility would be to pass all the simple properties of this object so that the default model binder can reconstruct it at the target location:
You could also pass only a message id:
and have the message object being reconstructed in the details action using this id:
and this job could be greatly done by a custom model binder for the
MessageUitype.Another possibility would be to use
TempDataorSession:and then inside the Details action: