views:

683

answers:

3

I'm using ASP.NET MVC (v1.0) on an app and want to integrate simple client-side form validation. IE: Numeric-Only fields, required fields, etc.

Is there good, and potentially eye-candy fancy, method of validating in jQuery on the client that will cancel form submission on failed validation?

I've perused and experimented with quite a few of the jQuery form plugins available on the jQuery site already. But I've not found one yet that hijacks the form submission; MVC always routes to my controller action without validating.

+3  A: 

I can report that I use the validation plugin and it works as advertised. Have you checked that you're not having javascript errors that are causing no javascript to run and thus not preventing the default submission mechanism to go through? I ran into this problem with AJAX form submissions when I was missing one of the AJAX javascript libraries.

tvanfosson
I haven't tried that one yet. Looking into it now. More to come...
Boydski
Well, I've worked with it quite a bit, but I just haven't been able to get the right combination that will actually stop form submission. Might you have a snippet laying around? {-o)
Boydski
$(document).ready( function() { $('form').validate(); } ); is all it should really take.
tvanfosson
+3  A: 

Suggest you take a look at xVal, a validation framework for asp.net mvc. It uses the jQuery validation plugin, integrated to serverside validation and lots more ….

xVal

To quote

xVal is a validation framework for ASP.NET MVC applications. It makes it easy to link up your choice of server-side validation mechanism with your choice of client-side validation library, neatly fitting both into ASP.NET MVC architecture and conventions.

Cherian
+1  A: 

Have a look at this blog article. It describes how to automatically generate client-side validation rules with xVal and also how to automatically implement remote client-side validation.

Adrian Grigore