在我的模型中,我有这个:
[RequiredIf("Operation", 2)]
public string Test_Type { get; set; }
我正在使用MVC Fool Proof Validation。
在我看来:
<div class="col-md-6 form-group">
<label class="col-md-4 control-label">Operation Type: <span class="fa fa-asterisk text-danger"></span></label>
<div class="col-md-8">
@Html.DropDownListFor(model => model.Operation, (IEnumerable<SelectListItem>)ViewBag.OperationChoice, "-- Select Operation --", new { @class = "form-control" })
<br />
@Html.ValidationMessageFor(model => model.Operation, "", new { @class = "text-danger" })
</div>
</div>
<div class="row" id="TestType-div">
<div class="col-md-6 form-group">
<label class="col-md-4 control-label">Type Of Test: <span class="fa fa-asterisk text-danger"></span></label>
<div class="col-md-8">
@Html.DropDownListFor(model => model.Test_Type, (IEnumerable<SelectListItem>)ViewBag.Test_TypeChoice, new {@class = "form-control"})
<br/>
@Html.ValidationMessageFor(model => model.Test_Type, "", new { @class = "text-danger" })
</div>
</div>
</div>
此验证有效,但它没有Test_Type
以红色轮廓突出显示带有 css 类的下拉列表input-validation-error
。如何RequiredIf
以一种在表单无效时突出显示具有input-validation-error
类名的字段的方式使用注释?
在线查看此代码 Codepen.io