I am attempting to pass a model with a list property from the view, to the post action. The list comes back null on post, but we need the list with the new items to update their information. My model looks like this:
public class Person()
{
internal string Name {get;set;}
internal decimal Age {get;set;}
internal List<int> Rate {get;set;}
}
The view is populated with their current information, and we use a foreach to iterate through the list, and produce text boxes for the editing capability. When the person hits submit after editing the desired values, the view will go to an [HttpPost] action, but the values are null.
The view is surrounded with a @using (Html.BeginForm(Model)) and on submit, the model is passed to the post action, but the list is null. All other values are populated.
Any Ideas? P.S. we are using c# and Razor View Engine sorry but the list still is not passing to the model here is the 4 loop.
@{ int i = 0;}
<table>
@for (i = 0; i < Model.VendorContracts.Count; i++ )
{
if (i == 0)
{
<tr>
<th>
Vendor Contracts
</th>
<th>
Effective Date
</th>
</tr>
}
if (i < 5)
{
<tr>
<td>@Model.VendorContracts[i]
</td>
<td>@Html.TextBoxFor(model => model.EffectiveDates[i])</td>
</tr>
}
if (i == 5 || i == 10 || i == 15 || i == 20)
{
@:</table>
@:<table>
}
if (i >= 5)
{
if (i == 5 || i == 10 || i == 15 || i == 20)
{
<tr>
<th>Vendor Contracts
</th>
<th>
Effective Date
</th>
</tr>
}
<tr>
<td>
@Model.VendorContracts[i]
</td>
<td>@Html.TextBoxFor(model => model.EffectiveDates[i])</td>
</tr>
}
}
</table>