views:

38

answers:

1

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?

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?

+2  A: 

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.

Alastair Pitts
thx for your input, really appreciate it!
Ari