如何在后期请求中调用输入字段以使它们正确匹配?
public class ViolationTypes
{
public int ViolationTypeId {get; set; }
public string ViolationDate {get; set; }
}
public List <ViolationTypes> ViolationTypeIds {get; set; }
我将其命名为但不起作用
var name1 = String.Format ("{0} .ViolationTypeIds [{1}]. ViolationTypeId", prefix, item.Value);
var name2 = String.Format ("{0} .ViolationTypeIds [{1}]. ViolationDate", prefix, item.Value);
前缀 - 这是当前的标签
查看:
foreach (var item in items)
{
var name1 = String.Format("{0}.ViolationTypeIds.ViolationTypeId", prefix, item.Value);
var name2 = String.Format("{0}.ViolationTypeIds.ViolationDate", prefix, item.Value);
var id1 = fieldName + "_" + item.Value;
<tr>
<th style="width: 20px">
@if (isDisabled)
{
<input disabled="disabled" name="@name1" value="@item.Value" id="@id1" @(item.Selected ? "checked=\" checked\"" : string.Empty) />
}
else
{
<input type="checkbox" name="@name1" value="@item.Value" id="@id1" @(item.Selected ? "checked=\" checked\"" : string.Empty) />
}
</th>
<td>
<label for="@id1">@item.Text</label>
</td>
<td>
<input type="hidden" name="@name2"/>
</td>
</tr>
}
控制器:
public ActionResult Update([Bind(Exclude = "CurrentTab")]
TabViewModel currentTab, FormAction action){}
答案 0 :(得分:0)
尝试使用此构造来渲染模型。为简洁省略了标签,您可以自己添加。
@for (var index = 0; index < Model.ViolationTypes.Length; index++)
{
@Html.HiddenFor(x => Model.ViolationTypes[index].ViolationTypeId)
@Html.CheckBoxFor(x => Model.ViolationTypes[index].Value)
@Html.HiddenFor(x => Model.ViolationTypes[index].ViolationDate)
}