我是一名有用的助手,可以帮您进行文本翻译。
我有一个模型,希望为其创建一个批量更新页面,但是遇到了问题。
我的视图模型:
public class ApproveView
{
public IEnumerable<MyObject> ObjectList { get; set; }
}
我认为:
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 />
}
这段代码循环遍历我的对象并输出表单。问题在于,所有同一类型的字段都具有相同的名称。因此,例如,我所有的单选按钮都是相关的,我只能选择其中一个。
我该如何使每个字段的名称唯一并与该对象关联?我是否走上了正确的道路,还是有更好的方法来做到这一点?