5

MicrosoftMvcJQueryValidation.js is used by ASP.NET MVC 2 for client side validation.

Having problems with this file just not working properly and wondering if I have the wrong version.

The version I am using came from the source for futures.

 MicrosoftMvcJQueryValidation.js
 5,626 bytes
 11/17/09 10:43:12am

There are two reasons i think i have the wrong version :

1) I actually have to call this code to get the validation routine working at all. This is because the default client validation function now embedded into FormContext.cs is Sys.Mvc.FormValidation.enableClientValidation .

 ViewContext.FormContext.ClientValidationFunction = "EnableClientValidation";

2) There is some code from jquery.validate.js which does the followin :

  this.settings.errorPlacement
    ? this.settings.errorPlacement(label, $(element) )
    : label.insertAfter(element);

This calls into this function in MicrosoftMvcJQueryValidation.js :

 errorPlacement: function(error, element) {
        var messageSpan = fieldToMessageMappings[element.attr("name")];
        $(messageSpan).empty();
        $(messageSpan).removeClass("field-validation-valid");
        $(messageSpan).addClass("field-validation-error");
        error.removeClass("input-validation-error");
        error.attr("_for_validation_message", messageSpan);
        error.appendTo(messageSpan);
    },

The problem is that element has been wrapped by jQuery.validate with the jQuery $(element) expression.

Therefore element.attr("name") is undefined, but element[0].attr("name") is valid.

I've taken MicrosoftMvcJQueryValidation.js from the futures download on Microsoft's site. `

I cant find any other MicrosoftMvcJQueryValidation version - but I'm sure there must be one. Can anyone help?

Eilon
  • 25,582
  • 3
  • 84
  • 102
Simon_Weaver
  • 140,023
  • 84
  • 646
  • 689
  • Can you please clarify which preview of ASP.NET MVC 2 you are using? There is no "Beta 2" but there is a Preview 2 as well as a Beta and an RC. ASP.NET MVC 2 Preview 2 is also included in Visual Studio 2010 Beta 2. Yes, it's confusing! – Eilon Dec 26 '09 at 22:11
  • OK well this question is somewhat out of date now that there is an RC. please see my other question http://stackoverflow.com/questions/1934803/how-do-i-use-microsoftmvcvalidation-js-without-having-to-include-microsoftajax-js which should help – Simon_Weaver Dec 27 '09 at 01:39
  • oh and I meant Preview 2 (well RC wasnt out when i wrote this question anyway) – Simon_Weaver Dec 27 '09 at 01:40

1 Answers1

6

As of Dec 17, 2009 the latest version of MicrosoftMvcJQueryValidation.js is available in the futures download project.

Be careful to include MicrosoftMvcJQueryValidation.js and NOT the similarly named MicrosoftMvcValidation.js.

Community
  • 1
  • 1
Simon_Weaver
  • 140,023
  • 84
  • 646
  • 689
  • 1
    Is this code still relevant now vs2010 has shipped as futures link is dead, where will I find this js file? – Anthony Main May 02 '10 at 13:10
  • 2
    You can find it in either the "ASP.NET MVC 2 RTM Source Code" or in the "ASP.NET MVC 2 Future", both avalable at: http://aspnet.codeplex.com/releases/view/41742 – Ulf Lindback Jun 04 '10 at 07:49
  • @tigermain Even though VS 2010 has shipped (for awhile at the time of this writing), what's indicated here still seems to be the right place to find MicrosoftMvcJQueryValidation.js. If I create a new project in VS for an MVC 2 (non-futures) project or even an MVC 3 Preview 1 project this file isn't in the project by default. I'm assuming if I still MVC 2 futures and created a new project it would be there, though. – Derek Morrison Sep 01 '10 at 13:18