1

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:

  1. I want to display forms, and switch between them via a drop-down menu (or through links) without having to go back and hit the server every single time.
  2. I want the user to be able to select points on a Chart Control and have portions of the page refresh with the appropriate data depending on what he/she selects (partial page refresh).

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?

1
  • When you were using the ScriptManager and WebForms event handlers to accomplish those partial rendering tasks, you were going back and hitting the server every time. Those partial updates are actually more server intensive than a full page refresh, no matter how small an area is actually re-rendered. Commented Jun 9, 2010 at 18:22

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.