Which one is better to use in ASP.NET MVC?
I would like to mention that Microsoft supports JQuery, and they will make support for it in upcoming versions of Visual Studio. For more information please visit http://live.visitmix.com/. ASP.NET AJAX and jQuery does not overlap much, so you would like to use both.
JQuery is purely client side library. Asp.Net Ajax includes both client side and server side functionalities. IMHO, comparison ain't really fair. They might complement each other going by Microsoft's plans.
There is a variant of ASP.NET AJAX for MVC -- used with the AjaxHelper and extensions. This works well in concert with jQuery. I have instances where I use both on the same page; using MVC AJAX to update a DIV based clicking a button and using jQuery to get JSON data for a different operation on the same page. Standard ASP.NET AJAX (UpdatePanels, etc.) should be used in the WebForms world, not in MVC.
Personally, despite the HtmlHelper support for ASP.NET Ajax, I find jQuery ajax in conjunction with the JQuery forms plugin to be the nicest way to do ajax form posts in ASP.NET MVC.
e.g. with a jquery call on an html product list page with a form for each product allowing the item to be added to a basket, a single line of jquery code can 'ajaxify' all the forms on the page
$(".productListItem form").ajaxForm({ target: '#extraInfoSection' });
combined with a simple 'IsAjaxRequest' property on a controller base class that checks the headers:
Request.Headers["X-Requested-With"] == "XMLHttpRequest"
and some logic in the Controller to return the correct response type:
return IsAjaxRequest ? (ActionResult) View("BasketPartial", basket) : new RedirectBackToReferrerActionResult();
you have a form that works even with javascript turned off and no ASP.NET Ajax involved.
First of all, it could be useful to take in mind that ASP.NET MVC doesn't support, or better, doesn't has the postback concept..
- asp.net ajax it's based on the post-back, server-side mechanism, it's mission it's to make more easy to integrate ajax features in a server-side mode
- jQuery, as other frameworks (eg Extjs) implements a pure client-side ajax
It's still possible to use asp.net server controls in asp.net mvc, asp.net ajax it's one of them, but asp.net mvc it's made, it was thought, to separate concerns (views) and to be REST styled as close as possible, so taking this in mind the final thought would be:
- Using ASP.NET Web Forms ASP.NET AJAX it's the right choiche
- Using ASP.NET MVC it's better to try to go client, so jQuery (or others) is the better
Sorry for my english
Use ASP.NET AJAX with Web Forms and jQuery with ASP.NET MVC
Instead of making a recommendation I suggest you read Dave Ward's blog Encosia that has a series of posts on MS Ajax/ Update Panel vs. jQuery post mechanism. Dave maintains that the performance of jQuery is vastly superior as it cuts out approximately 100K from the transmission to and from the server.
Personally I prefer jQuery for the following reasons:-
- The plug-in community is far more varied and attracts developers from a broad range of backgrounds (not just the MS stack). For MS-AJAX you're pretty much constrained to the clientside AJAX control toolkit for your UI widgets at the moment.
- I find the jQuery API far more applicable common clientside tasks than that offered by MS AJAX
- Given the lack of WebForms smoke and mirrors going on in MVC you sometimes need a firm control over the DOM to do certain things, the CSS selector engine offered by jQuery really helps you do this.
In terms of what MS AJAX offers you in MVC, it can do a lot for you in terms of giving you a quick way to "AJAXify" forms and links, but as far as I'm concerned adding 90kb worth of javascript to do that isn't really worth it when the equivalent calls in jQuery (e.g $.get, $.post, $(element).load) are relatively easy to use.
Another alternative you probably could look at is Ajax.NET, http://www.ajaxpro.info/. I reckon it's better than ASP.NET AJAX for WebForms. It's runnable under MVC as well.
First of all, you could use either, as long as when you are talking about Microsoft Ajax, you are only referring to the client library. You can use the MS Ajax client library and most of the toolkit extenders without any server side controls. I have built a pretty big application using web forms and Microsoft Ajax then converted it to MVC/jquery. I found that I was using less and less of the features in the MS Ajax library. There is so much available with plugins, that its making even the ajax toolkit obsolete.
If you are talking about MS Ajax using update panels etc, then I would say no, you can't use them in MVC. In fact, don't use them at all! update panels are simulated ajax, the page still goes through its lifecylce almost defeating the purpose of using ajax.