views:

40

answers:

3

Many js files are included into Scripts folder by default in ASP.NET MVC 2 Projects. I suppose developers use jquery library nearly every time they program a site, but what about other files?

Please, can you tell scenarios and reasons when you:

  • Use Microsoft.Ajax instead of jquery or mix both libraries
  • Use JQuery validation infrastructure instead of asp.net mvc one or combine them both

Thank you in advance!

P.S. there are also diferrent editions of the same file. Do you include different editions depenending on debug/release build?

A: 

I usually delete that folder and make a new one under "Content" with just jquery to start with. I feel more comfortable working with jquery instead of microsoft's ajax implementation so I don't need the script file related to Microsoft.Ajax.

And about validation, I like to use jquery.validate for the client side validation and dataannotations model validation for the server side. In MVC1 you would bridge both using a framework like xVal, haven't done it in mvc2 yet.

JoseMarmolejos
I do the same. See no reason to prefer Microsoft Ajax to JQuery. But hesitate about client-side validation. I feel nervous when combine jquery with server-side data annotations.
Andrew Florko
A: 

I would personally never mix two JavaScript libraries (MicrosoftAjax and jQuery) in the same project. Apart from the added download (your users would have to download twice as many JavaScript files) there is quite a bit of duplication - two ajax implementations, two validation implementations etc. As we all know DRY is a good thing to follow.

To me the only advantage of using MicrosoftAjax in an ASP.NET MVC project is that it has built-in server-side support - Ajax.Form, Ajax.ActionLink etc. Built-in client validation is also using it.

However all those things can be done with jQuery and from my experience I think jquery.validate works quite well with data annotations too. I have not found any issues so far.

korchev
Thank you. But JQuery knows nothing about server-side DataAnnotations (AFAIK). How do you keep validation code DRY? Rely only on asp.net mvc validators (client-side scripts + data annotations), use some middleware libraries like xVal or something?
Andrew Florko
There is a mvc JavaScript which makes the bridge with jquery.validate. Check the MVC futures release on codeplex.
korchev
+1  A: 

I cannot find any reason to prefer Microsoft AJAX library instead of jQuery. Same for validation. Also I would recommend you using a CDN network to serve static files such as jquery and jquery.validation. So start by removing everything in the Script folder and add only scripts you write yourself.

Darin Dimitrov
Thank you. AFAIK, JQuery knows nothing about server-side DataAnnotations. How to keep my validation (client-side + sever-side) code DRY? Should I rely only on asp.net mvc validators only(client-side scripts + data annotations), use some middleware libraries like xVal or something?
Andrew Florko