Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Quick and Dirty Explanation of MVC3 Ajax/JS files, please :)

I've been trying to find a decent article or snippet that explains what the difference is in JS (Validate & Ajax) files are Microsoft includes with MVC3 and I've not been able to find anything.

Would someone kindly explain the differences and how they're supposed to be use (e.g. does one piggy-back off the other, used instead for X reason, etc):

  • jquery.validate, jquery.validate.unobtrusive and MicrosoftMVCValidation
  • jquery.unobtrusive-ajax, MicrosoftAjax & MicrosoftMVCAjax

To add on to this - basically why would I use jquery.validate vs. the unobtrusive or MVC validation. Or what is their purpose in conjunction with jquery.validate, etc. Likewise for the Ajax files.

Thanks a ton in advance :)

like image 337
Joshua Avatar asked Jul 12 '11 15:07

Joshua


1 Answers

Here are my 2 cents:

  • (jquery.validate and jquery.validate.unobtrusive) vs (MicrosoftMVCValidation)

Pick the first as it is unobtrusive meaning that HTML5 data-* attributes are generated on the input fields and validators are unobtrusively attached into separate javascript files. With Microsoft validation your final markup is no longer markup but it is markup mixed with javascript. Not only that this increases the size of your HTML pages but it makes them uglier and impossible to benefit from the browser caching capabilities of external static resources.

Depending on the project I decide whether I would use directly jQuery.validate plugin or benefit from the autogenerated HTML5 data-* attributes and let the jquery.validate.unobtrusive script do the automatic client script validation based on some DataAnnotations rules on my view models. Well, actually I don't use DataAnnotations but FluentValidation.NET but it doesn't matter to the client side as they both emit ModelMetaData. I must agree that with ASP.NET MVC 3 Microsoft made a step forward with those jquery.validate.unobtrusive scripts. But basically it will really depend on the project I am working on and the amount of control I need.

  • (jquery.unobtrusive-ajax) vs (MicrosoftAjax & MicrosoftMVCAjax)

None of the above :-) I would recommend you using pure jQuery but if you had to pick between the jquery.unobtrusive-ajax and MicrosoftAjax pick the first for the exact same reasons as the previous one. Now I should probably explain why I don't like either. I have already pointed out the complete crapiness of all Microsoft* scripts so let's not repeat it again. Even Microsoft themselves realized their mistake and starting from ASP.NET MVC 3 jQuery becomes the default library and their scripts are only included for compatibility with older applications that you might be converting, but I guess in future versions they will disappear completely. The question is why pure jQuery compared to jQuery.unobtrusive-ajax? Well, with the first I have far more control over the events of the AJAX requests. With jquery.unobtrusive-ajax for example when JSON objects are returned in the OnSuccess callback they are not automatically parsed into javascript objects you will have to do the parsing manually and that is just driving me nuts.

like image 161
Darin Dimitrov Avatar answered Oct 25 '22 07:10

Darin Dimitrov