I have a simple form and within I'm using Html.DisplayFor()
method to show some values. There is a submit button also within the form, which is triggering an update.
The question is开发者_开发问答 how to "refresh" the Display method(using AJAX). The particular action method must return a ActionResult
. I see the only solution in putting the display method in a partial view or is there any other option ?
You can use jQuery AJAX methods fairly easily to do this. Wrap the area you want to update in a DIV and give it an ID (say "ajax_panel") and then call a jQuery function when your submit button is clicked:
$.ajax({
url: '/YourController/ActionMethod>',
success: function(data) {
$('#ajax_panel').html(data);
}
});
Get the ActionMethod() to return the View you want and use a partial view to render it. I found this article useful when I tried to do something similar.
精彩评论