I have an Edit form where the user can disable MVC 4 client side validation for certain fields.
I am disabling the client side validation with jQuery:
$("#CustomerOrderNumber").prop("disabled", true);
This work fine when the form is first rendered.
The problem arises when I post back the form and then redisplay the form from a controller like this:
[HttpPost]
public ActionResult RegisterImei(ImeiCustOrderNumberModel model)
{
return View(model);
}
Because when the form is rendered again, the disabled validation in no longer disabled, and the unwanted client side validation for the field is active again.
It seems that this is determined by the original source markup:
<input class="text-box single-line" data-val="true" data-val-required="The Customer Order Number field is required." id="CustomerOrderNumber" name="CustomerOrderNumber" type="text" value="SF1861-" />
Any ideas on how to keep client side validation disabled when a form is rendered again after post back?
I have made a little sample app illustrating my problem.
If the user disable Field B the user can post back the model without Field B being validated.
But when the page renders again, it has forgotten that Field B was disabled.
And the unwanted client side validation message for Field B renders.
I want my page to remember that Field B was disabled and stop rendering client side validation messages.
Mvc4SampleApp.zip:
http://sdrv.ms/14FUKa6