I have an MVC5 project where I am trying to Post a List of 'Permissions' back to the server.
@model List<ConnectConsole.Models.Permissions>
<form action="/products/@{@Html.Raw(Url.RequestContext.RouteData.Values["id"])}/permissions/save" method="POST">
@for (int i = 0; i < Model.Count; i++)
{
@Html.TextBoxFor(model => model[i].ConnectId)
@Html.DropDownListFor(
model => model[i].ScopeVal,
Model[i].ScopeTypes,
"-- Please Select --")
}
<button class="btn btn-full btn-submit">Save</button>
@* removed some html for brevity *@
</form>
The Data that is posted back to the server looks somthing like this (copied from chrome)
[0].ConnectId:88709d85-710c-45da-8fec-0ee661d267b1
[0].ScopeVal:e276964f-7e6e-4aaf-8bf5-cac5b02f3a8f
[1].ConnectId:78709d85-710c-45da-8fec-0ee661d267b1
[1].ScopeVal:
[2].ConnectId:68709d85-710c-45da-8fec-0ee661d267b1
[2].ScopeVal:
My C# model
public class Permissions
{
public String ConnectId { get; set; }
public List<SelectListItem> ScopeTypes;
public String ScopeVal;
}
Method signature that I am posting to
public ActionResult Save(string id, List<Permissions> permissions)
The object seems to be correctly posted to the server with all with all fields in the request but in the method the list that gets serialized from this data only contains the connect ID, it is of the correct size and I get a list that has 3 objects in it but ScopeVal is never set.
Is this a bug in MVC or am I doing something horribly wrong?