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?
I use ajax calls for this
$('.btnSave').on('click', function(){
$.ajax({
url: '@(Url.Action("SavePerson", "Meeting"))',
type: 'post',
data: {
Value1: 'Value1',
Value2: 'Value2'
},
success: function (result) {
alert('Save Successful');
}
});
});
and put the call in a button click or a link click if you want with href = # hopefully this helps.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With