Model:
[Display(Name = "City"]
[Required]
[RegularExpression(@"^(?!d$).*$"]
[StringLength(20,MinimumLength = 2]
public string City { get; set; }
Form:
@Html.LabelFor(x => x.City, new { @class = "control-label" })
@Html.TextBoxFor(x => x.City, new {id="city" })
Script:
<script>
$(document).ready(function () {
$("#identificationForm").submit(function (e) {
var required=document.getElementById("city").required;
console.log(required);
// e.preventDefault();
});
});
</script>
I want to remove required property if some condition is met.Unable to do this this way.How can i achieve this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…