user137348
user137348

Reputation: 10332

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

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 ?

Upvotes: 0

Views: 332

Answers (1)

Dan Diplo
Dan Diplo

Reputation: 25339

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.

Upvotes: 1

Related Questions