Update two DIVs on AJAX success - combine JavaScriptResult and PartialViewResult?

At the moment I have jQuery doing a POST to a controller that returns a ContentResult. When the OnSuccess event is fired from jQuery, it updates the div with the returned data. Now I want to update another DIV with model data.

I think I have a RenderPartial, make a post and return a PartialResult that will handle this new div, but what about the DIV I filled earlier?

Is it possible to combine JavaScriptResult and PartialResult? The JavaScript result handles the first DIV mentioned, and the PartialResult handles the new DIV.

thanks

+1


a source to share


2 answers


This is how I did it.

My main view is now RenderPartial ("PartialViewName", Model).

At the top of the partial view, I check to see if the ViewData ["AJAXReturn"] is not empty. If not, I call another partial view and pass in a ViewData ["AJAXReturn"] element that contains the original AJAX response.



In my Controller action method, I add my original response message to ViewData ["AJAXReturn"], then call methods to update the model data and return a PartialView ("PartialViewName", updatedModel).

Now the ViewData is not null, so the original DIV is populated via the ViewData, and calling the PartialView with the new model displays the second DIV. This is done by the OnSuccess event on the jQuery column, which executes $ ('# containsdiv'). Html (responsefromPartialViewreturn);

Hope this helps someone.

0


a source


While it adds more pipe noise, I think a cleaner option would be to make a separate call from your controller to grab an additional PartialResult, presumably in the OnSuccess event.



0


a source







All Articles