asp.net-mvc-helpers - 使用 MVC 助手的父子模型
问题描述
我有一个模型类Grade
,它有一个 int list 属性PayHeads
。我怎样才能用最简单的方法实现这一点,或者如果有另一种方法,请告诉我是 ASP.NET MVC 助手的新手,我不想使用 jQuery 或 Ajax:
public int GradeId { get; set; }
public int IncrementMonth { get; set; }
public List<int> PayHeadIds { get; set; }
看法
@using (Html.BeginForm("Save", "Grade", FormMethod.Post))
{
@Html.AntiForgeryToken();
@Html.HiddenFor(model => model.GradeId)
@Html.HiddenFor(model => model.Operation)
@Html.HiddenFor(model => model.PayHeadIds, new { @Id="hdnPayHeadIds" })
<div class="form-row">
<div class="form-group col-md-4">
@Html.LabelFor(g => g.Code, new { @class = " form required" })
@Html.TextBoxFor(g => g.Code, new { @class = "form-control", placeholder = "Code" })
@Html.ValidationMessageFor(g => g.Code, null, new { @class = "text-danger" })
</div>
<div class=" form-group col-md-3">
@Html.LabelFor(g => g.IncrementMonth, new { @class = "required" })
@Html.TextBoxFor(g => g.IncrementMonth, new { @class = "form-control", placeholder = "Increment Month" })
@Html.ValidationMessageFor(g => g.IncrementMonth, null, new { @class = "text-danger" })
</div>
<div class=" form-group col-md-3">
@Html.LabelFor(g => g.IsUnion, new { @class = "icheck-label form-label cursor-pointer" })
<br />
@Html.CheckBoxFor(g => g.IsUnion, new { @class = "skin-flat-blue", data_div = "divPF" })
@Html.ValidationMessageFor(g => g.IsUnion, null, new { @class = "text-danger" })
</div>
</div>
<hr />
<table class="table table-bordered" id="tblEmployeeExperience">
<thead>
<tr>
<th>#</th>
<th>Select</th>
<th>PayHead</th>
</tr>
</thead>
<tbody>
@if (ViewBag.PayHeadList != null)
{
int c = 0;
foreach (var p in ViewBag.PayHeadList)
{
c++;
<tr>
<td>@c</td>
<td>
<input type="checkbox" class="chkPayHead" id="chkPayHead(@p.PayHeadId)" value="@p.PayHeadId" />
</td>
<td>@p.Name</td>
</tr>
}
}
</tbody>
</table>
<button class="btn btn-success" type="submit">Submit</button>
<a href="@Url.Action("AddEdit", "Grade")">
<input type="button" class="btn btn-warning" value="Clear" />
</a>
<a href="@Url.Action("Index", "Grade")">
<input type="button" class="btn btn-dark" value="Back" />
</a>
}
我想在上面的 Int List 中获取选中的 PayHeadIds
解决方案
推荐阅读
- javascript - socket.io房间名称如何从前端传递到后端?
- django - ValidationError 未显示在模板中(尽管字段验证错误)
- reactjs - 如何将评级保存到本地存储,使其在刷新后不会消失?
- python - 可以采用 NaN 和 inf 值建议的线性回归库
- node.js - 试图从函数返回一个承诺的值
- swift - 迁移到 Combine 会导致 Snapshotlistener 失败
- python - 如何在远程 Linux shell(Python Admin SDK)中使用 Firebase Admin SDK 服务密钥 JSON 文件?
- swiftui - SwiftUI解码HTML实体报错:同时访问0x7ff43ff29b50,但修改需要独占访问
- python - pandas 数据帧中的对数回报 groupby 股票代码
- python - 如何使用 Python 和 matplotlib 绘制任意数学函数?