模型:
[Display(Name = "City"]
[Required]
[RegularExpression(@"^(?!\d$).*$"]
[StringLength(20,MinimumLength = 2]
public string City { get; set; }
形式:
@Html.LabelFor(x => x.City, new { @class = "control-label" })
@Html.TextBoxFor(x => x.City, new {id="city" })
脚本:
<script>
$(document).ready(function () {
$("#identificationForm").submit(function (e) {
var required=document.getElementById("city").required;
console.log(required);
// e.preventDefault();
});
});
</script>
如果满足某些条件,我想删除所需的属性。无法以这种方式执行此操作。我该如何实现?