I have a model that includes the following property:
[Required]
public string City { get; set; }
Basically, a user selects a stored value from a dropdown. The fields in my partial view are populated with the corresponding data. In certain circumstances, the stored data will not have a value for City. I am trying to use jQuery to check that if the field is empty, to basically not require the field and to allow submission. I have tried the following:
$("#City").attr("data-val", "false");
$("#City").rules("remove", "required");
$("#City").attr("disabled", "disabled");
$("#City").attr("aria-required", "false");
$("#City").removeAttr("required");
None of these work. On submit, the proper method is hit in the controller with a ModelState.IsValid of false and an error stating that "The City field is required."
How can I use jQuery to prevent this field from being validated on submit?