Why i can't pass this model to a controller in ASP.NET MVC?
This is my View:
@model Pro.WebUI.ViewModels.DataItemVm
<div>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.FirstSetList.FirstOrDefault().Name)
</th>
<th>
@Html.DisplayNameFor(model => model.FirstSetList.FirstOrDefault().Amount)
</th>
</tr>
@foreach (var item in Model.FirstSetList)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.TextBoxFor(modelItem => item.Amount)
</td>
</tr>
}
</table>
<hr/>
<div>
@using (Html.BeginForm())
{
@Html.HiddenFor(model => model.FirstSetList)
<input type="submit" value="Confirm"/>
}
</div>
</div>
After I click Confirm button - this method receives model with Count = 0;
public ActionResult FirstSet(DataItemVm model)
{
...
}
Of course my ViewModel DataItemVm has list:
public class DataItemVm
{
public List<FirstSetViewModel> FirstSetList { get; set; }
}
So it looks like that problem is only at view. Maybe BeginForm should be in other place? However HiddenFor should send be enough to send this model.