I'm in the process of converting my asp.net app to asp.net mvc. I'm using a master page which contains a div that currently renders a partial view. This partial view displays the model data that I want displayed.
I saved the "best" for last and that is to convert开发者_如何学Python an asp.net timer triggered update panel to MVC. I'm an asp.net MVC newbie. Any suggestions? I've seen an example in this forum that uses a form and a submit button. How do I add a timer? Do I simply set up a timer in my controller and every time in fires return my partial view? Do I even need the form? Thanks
Triggering AJAX requests at regular intervals to a controller action that returns a partial view should suffice:
public ActionResult SomePartial()
{
// return PartialView.ascx partial view containing an HTML fragment
return PartialView();
}
And in your javascript:
$(function() {
// trigger an ajax request to the controller action every 5s
// and inject the returned HTML fragment into a div with id="result"
window.setInterval(function() {
$('#result').load('/home/somepartial');
}, 5000);
});
Should update div
tag with id="result"
in the markup:
<div id="result"></div>
精彩评论