【发布时间】:2016-05-16 10:51:55
【问题描述】:
这是我的查看代码:
<div class="form-group-1">
@Html.LabelFor(model => model.device.HasAMC, htmlAttributes: new { @class = "control-label col-lg-4" })
@Html.EditorFor(model => model.device.HasAMC, new { htmlAttributes = new { @class = "form-control" } })
</div>
<div class="form-group-1" id="HasDate">
@Html.LabelFor(model => model.device.AMCExpiredDate, htmlAttributes: new { @class = "control-label col-lg-4" })
@Html.EditorFor(model => model.device.AMCExpiredDate, new { htmlAttributes = new { @class = "form-control", placeholder = "AMCExpireDate(MM/dd/yyyy)", required = "required", title = "Enter AMC Expire Date" } })
</div>
<button style="margin-left:33%;" class="btn btn-sm btn-primary col-lg-2 " type="button" name="action" onclick="javascript:Save(@ViewBag.DealerId);" value="SaveDeviceInfo"><strong>Save</strong></button>
在此我需要设置必填字段“AMCExpiredDate”,例如“HasAMC”的值是否选择“true”,然后对必填字段应用验证,如果为假,则从“AMCExpiredDate”中删除验证。
这在 MVC 中可能吗? 请帮我。提前致谢。
【问题讨论】:
-
考虑一个foolproof
[RequiredIf]或类似的验证属性(或者你可以自己写) -
只用 jquery 做,onchange 事件,将验证属性添加到下拉列表
标签: jquery asp.net-mvc validation