2

I have a view which has multiple submit buttons. One button is for going back to another action which does some processing and load previous view.

However, in current view, it has some validations for model. So, when the button is click, it will show validation error.

Is there a way to get around this? or, we have to validate the data on server side?

Thanks

2
  • You can put the cancel class on your button. This will bypass the jquery validation <input type="submit" value="Do not validate" class="cancel" /> Commented Oct 11, 2014 at 17:51
  • cool, is this because of jquery-ui? please add it as answer. thanks. Commented Oct 11, 2014 at 18:01

3 Answers 3

2

The built in client side validation in ASP.NET MVC uses the jquery validation plugin under the hood where you can skip validation while still using a submit-button with adding class="cancel" to that input:

<input type="submit" value="Do not validate" class="cancel" />

See this also in the documentation.

Sign up to request clarification or add additional context in comments.

Comments

1

You can cancel validation by doing this:

$('#yourButton').click(function() { 
    $('input, textarea, select', '#yourForm').each(function () {
        $(this).attr('data-val', 'false');
    });
})

or

$("#yourButton").click(function() {
    $('#yourForm').removeData('validator');
    $('#yourForm').removeData('unobtrusiveValidation');
    $('#yourForm').validate().cancelSubmit = true;
    $('#yourForm').submit();
});

Comments

0

class ="cancel" is now replaced by formnovalidate attribute

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.