asp.net mvc 2 - Using RedirectToAction with custom type parameter -
asp.net mvc 2
i have action in identity controller
public actionresult details(string id, messageui message) {
and i'm trying redirect action controller, don't know how should pass message parameter
i trying with
var id = "someidvalue" var message = new messageui("somevalue"); return redirecttoaction("details", "identity", new { id, message}); }
but message parameter null
that's normal. cannot pass complex objects in urls when redirecting , that's reason why messageui
object not received. scalar properties translated &
-separated key/value pairs in url.
one possibility pass simple properties of object default model binder can reconstruct @ target location:
var id = "someidvalue" var message = new messageui("somevalue"); return redirecttoaction("details", "identity", new { id = id, messageprop1 = message.messageprop1, messageprop2 = message.messageprop2, messageprop3 = message.messageprop3, });
you pass message id:
var id = "someidvalue"; return redirecttoaction("details", "identity", new { id = id, messageid = "somevalue" });
and have message object being reconstructed in details action using id:
public actionresult details(string id, string messageid) { var message = new messageui(messageid); ... }
and job done custom model binder messageui
type.
another possibility use tempdata
or session
:
var id = "someidvalue"; tempdata["message"] = new messageui("somevalue"); return redirecttoaction("details", "identity", new { id });
and inside details action:
var message = tempdata["message"] messageui;
Comments
Post a Comment