1

I'm looking for sample implementation/documentation of How to use IClientValidatable with MVC4 and jQuery.Validation. I've found this very good resource having everything here.

http://msdn.microsoft.com/en-us/vs2010trainingcourse_aspnetmvccustomvalidation_topic3.aspx

but problem with that with MVC4 there is no such thing as MicrosoftMvcValidation.js with mvc 4 project default script. And I need to have custom validation for client and server. so any documentation/codesnippet/how-to-guidelnes will be very much appreciated.

afr0
  • 848
  • 1
  • 11
  • 29

1 Answers1

2

Try using these scripts files that would work with IClientValidatable

<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>

These are in Scripts folder of your project you can reference these scripts to get it work

Karthik Chintala
  • 5,465
  • 5
  • 30
  • 60
  • based on my experience I don't recommend jquery.validate. If your form has so many fields the entire IE will hang or frezee for several seconds. That's also the complaint of other developers. See http://forum.jquery.com/topic/plugin-validate-freezes-ie-when-form-have-too-many-elements – Jobert Enamno Mar 12 '13 at 05:04
  • @karthik I'm already using this. Actually I dont know how to extend it on client for custom validation. I do need to add my custom scripts on the client for using customvalidation if i'm not wrong. any documentation in this regards is what I'm looking for as don't have much knowledge on jQuery.validate.* – afr0 Mar 12 '13 at 05:05
  • 1
    @JobertEnamno so what would you suggest? – afr0 Mar 12 '13 at 05:06
  • @afr0 yes you can include the custom scripts after validate.min and validate.unobtrusive.min files – Karthik Chintala Mar 12 '13 at 05:11
  • @afr0 well what we did is writing our own validations namely created common function to validate textboxes and dropdownlist, radiobutton and checkboxes. That's quite tedious but well you can assure that the performance of your application to all browsers is great – Jobert Enamno Mar 12 '13 at 05:12
  • @afr0 here is a [link](http://dotnetgurukul.com/2012/02/03/asp-net-mvc-3-0-custom-validation-using-iclientdatable-jquery/) for using it in MVC3, but i hope it may work with mvc4. Also have a look at this post from [Scott Allen](http://odetocode.com/Blogs/scott/archive/2011/02/22/custom-data-annotation-validator-part-ii-client-code.aspx) – Karthik Chintala Mar 12 '13 at 05:18
  • I found this thread which works just find... bit slow in response i must admit. http://stackoverflow.com/questions/8284207/asp-net-mvc-implement-custom-validator-use-iclientvalidatable . One weird thing about it, that it doesn't stop form post even having invalid fields with proper validation error messages however server does recognize ModelState.IsValid as false... is this normal behavior? – afr0 Mar 12 '13 at 10:07