Reputation: 34632
I am currently developing a new website utilizing ASP.NET MVC2. Much of what I want to do with the website (from a front-end standpoint) involves AJAX-y-type tasks.
Two examples:
In both these cases, I am able to accomplish what I wish to accomplish using the traditional web forms event handlers, etc. Unfortunately, the use of a ScriptManager violates the spirit of MVC. It seems as if MVC prevents the use of many of the controls that are available to ASP.NET.
So, my question is: how do I use AJAX and make AJAX calls without utilizing ScriptManager and the web forms method of utilizing event handlers?
Upvotes: 1
Views: 2646
Reputation: 116977
It isn't that ScriptManager "violates the spirit" of MVC, it's just that the MVC framework is built differently.
Web controls rely on ASP.Net webforms constructs such as ViewState and Postbacks. These don't exist in ASP.Net MVC, so any controls relying on them will fail to function properly. However, controls will still render their HTML and run their event handlers, as each .aspx page still goes through the page lifecycle when it is compiled by the default view engine. (If you're using a custom view engine to render your html, they won't work at all!)
Anyway, most people rely on Microsoft's ajax scripts (MicrosoftAjax.js, MicrosoftMvcAjax.js) or use a third party library such as jQuery to do their ajax stuff. If you're just getting started, I would suggest heading over to the main ASP.Net MVC site and checking out some of their tutorials. The NerdDinner ebook is a great start to MVC, and there is a chapter on using Microsoft's Ajax to do dynamic updates.
Upvotes: 2