Quick and dirty explanation of MVC3 Ajax / JS files, please :)

I am trying to find a decent article or snippet explaining the difference in the JS (Validate and Ajax) files that Microsoft includes with MVC3, and I could not find anything.

If someone kindly explains the differences and how they should be used (for example, if he leans back from another, is used instead for reason X, etc.):

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

To add to this - basically why should I use jquery.validate against unobtrusive or MVC checking. Or what is their purpose combined with jquery.validate etc. Similarly for Ajax files.

Thanks for the ton in advance :)

+6
source share
1 answer

Here are my 2 cents:

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

Choose the first one, as this is unobtrusive, which means that HTML5 data attributes are generated in the input fields, and the validators are unobtrusively tied to individual javascript files. When checking Microsoft, your final markup is no longer markup, but markup mixed with javascript. Not only does this increase the size of your HTML pages, but it makes them uglier and impossible to use the browser caching capabilities of external static resources.

Depending on the project, I decide whether I will use the jQuery.validate plugin directly or use the HTML5 * auto-generated data attributes, and let the jquery.validate.unobtrusive script automatically test the client script based on some DataAnnotations rules on my view models. Well, actually I do not use DataAnnotations, but FluentValidation.NET, but it does not matter for the client side, since both of them emit ModelMetaData. I have to agree that with ASP.NET MVC 3 Microsoft took a step forward with such jquery.validate.unobtrusive scripts. But basically it will really depend on the project I'm working on, and on the amount of management needed.

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

None of the above :-) I would recommend you use pure jQuery, but if you had to choose between jquery.unobtrusive-ajax and MicrosoftAjax, choose the first for the same reasons as the previous one. Now I probably should explain why I don't like it either. I have already pointed out the full complexity of all Microsoft * scripts, so do not repeat them again. Even Microsoft itself recognized its mistake and, starting with ASP.NET MVC 3, jQuery becomes the default library, and their scripts are included only for compatibility with older applications that you can convert, but I assume that in future versions they will completely disappear. The question is, why is pure jQuery compared to jQuery.unobtrusive-ajax? Well, with the first, I have much more control over AJAX request events. For example, with jquery.unobtrusive-ajax, when JSON objects are returned in the OnSuccess callback, they are not automatically processed in javascript objects, you have to manually parse and it just infuriates me.

+7
source

Source: https://habr.com/ru/post/892587/


All Articles