I know this question has been asked a zillion time but pardon me as I have wasted quite a number of hours now, thus finally posting it.
So to summarize I have a a view Model having some complex type prperties and a complex type list property .
public class ViewModel
{
public ViewModel()
{
Gains = new List<Gain>();
}
[UIHint("Common")]
public AllRegRecordsLog commonRegisterFields { get; set; }
public Potential Potential { get; set; }
[UIHint("Gains")]
public List<Gain> Gains { get; set; }
public void CreateGains(int count = 1)
{
for (int i = 0; i < count; i++)
{
Gains.Add(new Gain());
}
}
}
now my view createOrEdit I call this property as ,
@Html.EditorFor(model => model.Gains)
I have placed an editor template inside my specific view folder
@model Gains
table id="gainsTable" class="content-tables"style="width:98%">
<tr id="defaultGainsRow">
<td class="editor-label">
@Html.LabelFor(model => model.VolumeGainLow)
</td>
<td class="editor-field">
@Html.TextBoxFor(model => model.VolumeGainLow)
@Html.ValidationMessageFor(model => model.VolumeGainLow)
</td>
</tr>
<tr>
<td colspan="4">
<input id="addGainsButton"type="button" class="t-button" Value="Add Potential Gains"/>
</td>
</tr>
</table>
But somehow I get the error “The model item passed into the dictionary is of type ‘System.Collections.Generic.List but expects Gains”
I am using asp.Net MVC 4
Please point me in right direction.
Thanks
Bilal
Thanks for assistance guys I solvex it using the following post
http://ivanz.com/2011/06/16/editing-variable-length-reorderable-collections-in-asp-net-mvc-part-1/