mvc复杂模型表单提交
在mvc中如何使用复杂的模型表单,如list<model>,或者model中包含list<model>字段。
list<model>案例:
@model List<RTSafe.ZTSD.BusinessModules.DanModules.Models.OpConditionCheckModel>
@Html.AjaxEditorForm(width: 400, isDialog: false, ajaxOptions: new { success = "success" },
formBody:
@<div class="ztsd_table_rt">
<div class="ztsd_table_box">
<table>
<tr hidden="hidden"><th></th><td>@Html.HiddenFor(m => m[0].Dan_MonitorEvaluateId) @Html.HiddenFor(m => m[0].OperationCheckId)</td></tr>
<tr><th>@Html.LabelFor(m => m[0].ProjectName)</th><td>@Model[0].ProjectName</td></tr>
<tr><th>危险源名称</th><td>
@for (int i = 0; i < Model.Count; i++)
{
@Html.HiddenFor(m => m[i].Dan_MonitorEvaluateId)
@Model[i].DangerName @Model[i].AccidentName @("(" + Model[i].MonitorLevelName + ")") <br />
}</td></tr>
`<tr><th><span style="color:red">*</span>@Html.LabelFor(m => m[0].LicenseStatus)</th><td>@Html.CheckBox("LicenseStatus", true, new { @value = 0 })
<span>开工</span>
@Html.CheckBox("LicenseStatus", false, new { @value = 1 })
<span>整改后开工</span></td></tr>
<tr><th><span style="color:red">*</span>@Html.LabelFor(m => m[0].Conclusion)</th><td>@Html.TextAreaFor(m => m[0].Conclusion, new { style = "width:300px;height:50px;" })
@Html.HiddenFor(m => m[0].AttachmentJson, new { @class = "aaa" })
<span style="color:red">(请上传方案审批、技术交底记录、人员培训记录、设备清单、材料清单、应急物资准备等材料)</span>
<script>
$(".aaa").upload({
IsEdit: true, //是否为编辑
IsMulti: true, //是否为多选
Required: true, //是否为必须上传
selectLabel: "上传附件"
});
</script></td></tr>
<tr><th>@Html.LabelFor(m => m[0].LiablePerson)</th><td>@Html.Kendo().TextBoxFor(m => m[0].LiablePerson)</td></tr>
<tr><th>@Html.LabelFor(m => m[0].Contact)</th><td>@Html.Kendo().TextBoxFor(m => m[0].Contact)</td></tr>
<tr><th>@Html.LabelFor(m => m[0].CCusers)</th><td>@Html.Kendo().TextBoxFor(m => m[0].CCusers)</td></tr>
</table>
</div>
</div>
model中包含list<model>案例:
@model RTSafe.ZTSD.BusinessModules.DanModules.Models.CheckReviewInfoModel
@Html.AjaxEditorForm(width: 800, isDialog: false, ajaxOptions: new { success = "success" },
formBody:
@<div class="ztsd_table_rt">
<div class="ztsd_table_box">
<table>
<tr class=" " hidden="hidden">
<span class=" ">
@Html.HiddenFor(m => m.CheckReviewInfoId)
</span>
</tr>
<tr class="block-label">
<th>
<span>@Html.LabelFor(m => m.ProjectName)</span>
</th>
<td colspan="3" class="">
@Model.ProjectName
</td>
</tr>
@for (int i = 0; i < Model.ReviewList.Count; i++)
{
<tr class="block label">
<th>
<label class="lable1">重要危险源名称</label></th>
<td colspan="3">
@Html.HiddenFor(m => m.ReviewList[i].OperationCheckId) @Model.ReviewList[i].DangerName-@Model.ReviewList[i].AccidentName
@(Html.Kendo().DropDownListFor(m => m.ReviewList[i].ReviewStatus)
.DataTextField("Name").DataValueField("Id")
.DataSource(ds => ds.Read("GetReviewItems", "OpConditionCheck")).Events(m => m.Change("ChangeSelectItem"))
)
</td>
</tr>
<tr class="block label" id=@("NoPassReasonTr" + i) hidden="hidden">
<th></th>
<td colspan="3">@Html.LabelFor(m => m.NoPassReason) : @Html.Kendo().TextBoxFor(m => m.ReviewList[i].NoPassReason)</td>
</tr>
<tr class="block label">
<th rowspan="2">验收结论</th>
<td colspan="3">@Html.LabelFor(m => m.ReviewList[i].Conclusion):@Model.ReviewList[i].Conclusion</td>
</tr>
<tr class="block label">
<th>@Html.LabelFor(m => m.ReviewList[i].LiablePerson)</th>
<td colspan="1">@Model.ReviewList[i].LiablePerson</td>
<th>@Html.LabelFor(m => m.ReviewList[i].Contact)</th>
<td colspan="1">@Model.ReviewList[i].Contact</td>
</tr>
}
</table>
</div>
</div>
总结:对于model中包含不能为空的字段(例如int、guid等),需要设置一个隐藏的标签,例如:
@Html.HiddenFor(m => m.ReviewList[i].OperationCheckId) <!--OperationCheckId是不能空的guid类型-->

浙公网安备 33010602011771号