ASP.NET MVC 4 Passing Object Variable Through ActionLink

Umut Derbentoğlu picture Umut Derbentoğlu · Oct 14, 2013 · Viewed 16.8k times · Source

I have an ASP.NET MVC 4 application. There is a razor view in my application that works with List type as a model.

@model List<MeetingLog.Models.UserModel>

@{
    Layout = null;
}
.
.
.

I am iterating through Model variable like this:

@foreach (var item in Model)
                {
                    <tr>
                        <td>
                            @item.Name
                        </td>
                        <td>
                            @item.Surname
                        </td>
                        <td>
                            @Html.ActionLink("Click", "SavePerson", "Meeting", new {model = item, type = "coordinator"}, null)
                            @Html.ActionLink("Click", "SavePerson", "Meeting", new {model = item, type = "participant"}, null)
                        </td>
                    </tr>
                }

I need to pass two variables to SavePerson action with action links. First one is current UserModel, and second one is string variable named type. But in my action first parameter comes through as null. But string parameter comes correctly. How can I achieve this?

Answer

jannagy02 picture jannagy02 · Oct 14, 2013

You can not pass instances complex types through querystring. This is the way to use it:

@Html.ActionLink("Click", "SavePerson", "Meeting", new {x = item.x, y = item.y, ..., type = "participant"}, null)