views:

506

answers:

4

Hi

Looking at the new ASP.NET MVC framework it comes with javascript files for both ASP.NET AJAX and JQuery.

Can someone explain what ASP.NET AJAX gives me that JQuery doesn't?

Do I need to use both and can you give me examples where I would/would not need to use both?

I've used JQuery on plenty of non ASP.NET projects (PHP and prototype sites) and have used JQuery Ajax quite happily, but I'm unsure what's best to use for ASP.NET.

Thanks for your time Sniffer

+2  A: 

I've recently been writing ASP.NET MVC pages without Microsoft AJAX. Conclusions? You need to do a bit more wiring to get it working, especially with server side communications (tip: use JSON.NET, not the built-in stuff), but it is vastly shorter and more readable. I won't be using Microsoft AJAX again.

ASP.NET AJAX gives you:

  1. a bunch of ASP.NET controls that provide AJAX functionality. These are painful to use and even more painful to write. jQuery extensions are much cleaner, but have a steeper learning curve for an ASP.NET programmer.
  2. The ability to auto-generate classes which perform AJAX calls. This is really cool, but you can live without it.
  3. A namespace and event model, which you won't need if you program jQuery style.
  4. The ability to do partial renders of pages. Only useful if you're not using MVC, and rarely advisable even then.

Conclusion: Use jQuery, remove Microsoft AJAX.

Julian Birch
+1  A: 

A difference of opinion then(!), but thanks for the feedback.

For info, I found this thread which answers my questions a little more clearly.

http://stackoverflow.com/questions/492770/jquery-vs-microsoftajax-in-asp-net-mvc

I think I'll be going with just jQuery for the comfort factor, easier to read code, small file sizes, etc. and see how I go.

Thanks again Sniffer

Sniffer
And another thread which goes in favour of jQuery:http://stackoverflow.com/questions/794678/whats-the-point-of-asp-net-ajax-in-asp-net-mvc
Sniffer
A: 

I use JQuery for retrieving Json data and Microsoft AJAX for posting forms. You could do both with JQuery, but I don't really like serializing the form myself. At the end of the day Microsoft AJAX is pretty decent - if you need to write less JavaScript code yourself that's less code that you need to maintain.

So to answer your question - Microsoft AJAX doesn't really add anything that JQuery doesn't have. It simply allows you to use helpers which get translated to pretty much the same JavaScript code that you can write with JQuery. Like I said - less JavaScript code you write yourself is less code that you need to maintain.

There are no real examples of where you should or shouldn't use the one or the other - it comes down to personal preference IMO.

Jaco Pretorius
A: 

Asp.Net AJAX was designed for Asp.Net WebForms, not MVC. It was designed to do many things that jQuery already did. Before MS agreed that bundling jQuery with Asp.Net MVC was a good idea, Asp.Net AJAX was all they had.

Asp.Net AJAX tries to replicate part of the server side environment in the client's browser - you can see this with the MS-like JS namespaces. It was designed for WebForms when everything was based on the post-back model.

The MVC paradigm tries to decouple and simplify aspects of web development by being honest with how HTTP works. Asp.Net AJAX does not really fit in this space because of how tightly it was designed with WebForms. In the same way that you can hack get WebForms controls to work in MVC (because it's still built on the ASP.NET core) you can also get Asp.Net AJAX to work in MVC - but the real point is this:

jQuery and MVC (by design and definition) were meant for each other.

(hope my answer is not too subjective :D)

cottsak