ASP.NET MVC we use client side validation using jQuery.validate plugin, which will be based on Model – Data Annotation validation attributes.
In some cases we might want to disable such validation on a button click wherever it is not needed.
For example:
The below code block will register validation block for Title property in the Model, will result in client side validations fired when user click on button.
<div class="editor-field"> @Html.EditorFor(model => model.Title) @Html.ValidationMessageFor(model => model.Title) </div> <input type="submit" name="backButton" value="Back" title="Go back to Prev step." />
We can disable the client side validation check for a button using the “disableValidation=true” attribute for the button.
<script type="text/javascript"> document.getElementById("backButton").disableValidation = true; </script>
OR
<input type="submit" name="backButton" value="Back" title="Go back to Prev Step" disableValidation="true" />
OR
You disable client-side validation on a button by adding the css style class “cancel” to it.
That will look like below example:
<input type="submit" name="backButton" value="Back" title="Go back to Prev Step" class="mybtn-style cancel" />
These are the different ways you can disable the client side validations. Hope it was helpful.
Discover more from Cloud Distilled ~ Nithin Mohan
Subscribe to get the latest posts sent to your email.