开发者

How to send Complex Data (object) from view to controller?

I'm trying to pass this Person Object from my view to controller without Form, how do I do that?

Here's my attempt:

VIEW

 <%=Html.ActionLink(
 "Jump", 
 "Jump", 
 new { name="MyName", 
 person=ViewData["Person"]}, // lets assume ViewData["Person"] is not null
 null) %>

CONTROLLER

    public ActionResult Jump(string name, Person person)
    {
        return View();
    }

While Debugging the app in the Jump method, the name parameter shows "MyName", but Person parameter in null. Why does it behave this way?

开发者_StackOverflow社区

Is it because it only works for primitive types such as int, string, etc. and doesn't work for complex types such as that Person object?

What's the way around it?


You are correct in your assumption in regards to parsing complex types.

As this will be turned into an <a>, there is no easy way to serialise the Person object to fit in the href attribute.

Try passing some kind of unique primitive reference to the Person, such as an int or GUID.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜