I have a model that I would like have a mass update page for, but am having trouble.
My ViewModel:
public class ApproveView
{
public IEnumerable<MyObject> ObjectList { get; set; }
}
In my view I have:
foreach (var item in Model.ObjectList)
{
<div>
<table class="form" width="100%">
<tr>
<td>@Html.LabelFor(model => item.Accurate)<br />
@Html.RadioButtonFor(model => item.Accurate, true) Yes
@Html.RadioButtonFor(model => item.Accurate, false) No
@Html.ValidationMessageFor(model => item.Accurate)
</td>
<td>
@Html.LabelFor(model => item.Comments)<br />
@Html.TextAreaFor(model => item.Comments)<br />
@Html.ValidationMessageFor(model => item.Comments)
</td>
</tr>
</table>
@Html.HiddenFor(model => item.ID)
@Html.HiddenFor(model => item.CreatedOn)
@Html.HiddenFor(model => item.CreatedBy)
@Html.HiddenFor(model => item.ModifiedOn)
@Html.HiddenFor(model => item.ModifiedBy)
<hr />
}
This loops over my objects and prints the form. The trouble is that all of the fields of the same type have the same name. So, for example, all of my radio buttons are connected and I can only select one.
how do I make the names for each field unique and associated with that object? Am I even on the right track or is there a better way to do this?
Check this post: http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx
You need to create editor for your entity.
Hope it helps.
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