3

does anyone know if there is a way to trigger the client side form validation in a .Net MVC app manually? I want to do the following:

<script type="text/javascript">
    if([form valid]) {
        //do something
    }
</script>

I already looked through the code in MicrosoftMvcValidation.js but didn't find a method I could call on the form.

Mato
  • 830
  • 2
  • 9
  • 21

1 Answers1

5

I think the validation you are looking for can be found here: http://www.phpvs.net/2010/04/26/manually-validate-an-asp-net-mvc-form-on-the-client-side-with-microsoftmvcvalidation-js-and-jquery/

The deal is you need context of Sys.Mvc.FormContext, which has a .validate on it. This is what needs to be called. Just check out the blog post and you will be happy. :-)

CrazyDart
  • 3,803
  • 2
  • 23
  • 29