我应该如何在post请求调用输入字段
本文关键字:调用 输入 字段 请求 post 我应该 | 更新日期: 2023-09-27 18:07:06
我应该如何调用输入字段,他们将是正确的映射后请求?
public class ViolationTypes
{
public int ViolationTypeId {get; set; }
public string ViolationDate {get; set; }
}
public List <ViolationTypes> ViolationTypeIds {get; set; }
我将它命名为so,但不工作
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){}
尝试使用此构造来呈现您的模型。为简洁而省略的标签,您可以自己添加。
@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)
}