开发者

ASP.NET MVC 2: AJAX update and Html.Display()

开发者 https://www.devze.com 2022-12-27 03:36 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消