MVC 3 - AutoPostback with CauseValidation=false Behavior - asp.net-mvc-3

I'm familiar with the method of submitting a form via a change event like or a checkbox's check event. Most articles explain how to find the first form using jQuery and invoke it's submit() method. However, I wish to submit the form but not cause validation so the back-end can perform other actions. In my case, I have a dropdown that a users changes. Depending on the value, the back-end adds/removes certain controls. The issue I'm runing into is that the validation prevents the form from submitting.
Q: How do I submit the form so it does not perform client-side validation?

Remove the validation just before the form is submitted - check out the answers here How do I remove jQuery validation from a form?

I think you can just turn the validation off by calling #Html.EnableClientValidation(false)

Related

Invoking validation just after display the form JSF

I have a form where the user should be able to save even if there are validation errors.
These errors should be displayed once the user get into the form again.
So, i would like to invoke the validation of the entire form just after the form is displayed.
Currently, the validation is handled thru AJAX with several custom validators by using <f:validator/> and <p:ajax/> only when the user edits the field
Any suggestion is welcome!
Thanks!
An option would be to submit the form after it loads directly.
To achieve this you can use p:remoteCommand and something like jQuery('document').ready(function(){remoteCommandName()})

Validating form using jquery Ajax MVC

Up to this point, I’ve been using Microsoft Ajax for updates in my MVC app. I’m now switching to jQuery Ajax in order to standardize my approach.
However, I just realized that the required field in my model for the form did not fire and the user was able to submit the form even though some required fields were left blank.
What is the standard way to handle required fields if I’m handling my ajax functions using jQuery – i.e. I want the unobtrusive to handle my required fields by highlighting them and not allow the submit button to be clicked.
Also, to mention I am getting data-val attributes through the model.
P.S. I’m now using an event handler to detect click event on submit button for the form. In other words, I’m not using #using.Ajax.BeginForm to define my form.

What is triggering Unobtrusive Validation check in asp.net MVC 3

I'm trying to figure out how unobtrusive validation works in asp.net mvc 3.
I would like to know what is triggering the validation check when I click to submit the form. How is the script jquery.validate.unobtrusive.js bound to the form submit event ?
I also would like to know how can I manually prevent/trigger this check.
jquery.validate.unobtrusive is a validator for jquery.validate. It is like a extension.
jquery.validate.unobtrusive implements all the events and jquery.validate use it.
You can look into the jQuery.validate.js file and see that it uses the submit of the
form.
// validate the form on submit
this.submit( function( event ) {
...
If you want to trigger the validation by yourself you can call
$("#myform").valid()

ASP.NET MVC 3 jQuery client validation - disable for specific button (Ajax form)

How can I disable validation for one button inside the Ajax begin form?
Using jQuery validation I tried many ways from Google, but none of them worked (class="cancel", disableValidation attribute, etc.).
There may be other ways, but one for sure way is to remove all the validation rules if using unobtrusive validation via:
http://docs.jquery.com/Plugins/Validation/rules#.22remove.22rules
$('#frmMyName').validate().cancelSubmit=true;

MVC2 Validation

My application uses MVC validation explained here:
http://blog.stevensanderson.com/2010/01/28/validating-a-variable-length-list-aspnet-mvc-2-style/
And it works fine with both server and client validation when the form is posted. However my problem is that I would like to have client validation on one of the fields before the form is posted. So when the TextBox loses focus it is validated directly.
I have solved it by using jQuery validation on the field that is validated before the form is posted.
You must use JQuery validations so that it will validate before posting. It also highlights those area where validation fails.

Resources