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
a source to share
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.
a source to share