How do I make an update panel in the ASP.NET Model-View-Contoller (MVC) framework?
相关问题
- MVC-Routing,Why i can not ignore defaults,The matc
- How to fix IE ClearType + jQuery opacity problem i
- jQuery add and remove delay
- Include empty value fields in jQuery .serialize()
- Disable Browser onUnload on certain links?
Basically the 'traditional' server-controls (including the ASP.NET AJAX ones) won't work out-of-the-box with MVC... the page lifecycle is pretty different. With MVC you are rendering your Html stream much more directly than the abstracted/pseudo-stateful box that WebForms wraps you up in.
To 'simulate' an UpdatePanel in MVC, you might consider populating a
<DIV>
using jQuery to achieve a similar result. A really simple, read-only example is on this 'search' pageThe HTML is simple:
The data for the 'panel' is in JSON format - MVC can do this automagically see NerdDinner
SearchController.cs
and the jQuery/javascript is too
Of course UpdatePanel can be used in much more complex scenarios than this (it can contain INPUTS, supports ViewState and triggers across different panels and other controls). If you need that sort of complexity in your MVC app, I'm afraid you might be up for some custom development...
You could use a partial view in ASP.NET MVC to get similar behavior. The partial view can still build the HTML on the server, and you just need to plug the HTML into the proper location (in fact, the MVC Ajax helpers can set this up for you if you are willing to include the MSFT Ajax libraries).
In the main view you could use the Ajax.Begin form to setup the asynch request.
A partial view encapsulates the section of the page you want to update.
Then setup your controller action to handle both cases. A partial view result works well with the asych request.
Hope that helps.
If you are new to asp.mvc I recommend you to download the NerdDinner (source) sample application. You will find in there enough information to start working effectively with mvc. They also have ajax examples. You will find out you don't need and update panel.