开发者

Refresh several partial view

Is there a way to refresh several partial view from the controller ? (return View())

Thanks,

Update1: Example, the content pârt o开发者_如何学运维f my screen is divided in 2 parts, on the left a customer list on the right the details customer, the details of the customers selected in the list of the left. If I create an new customer, when I save, I'd lile refresh the list (left part) and see the details (right part)


Kris,

the only way i can think to do this simply is by having multiple partialviews embeded within the main 'view' to be refreshed. these would then be refreshed in the same cycle. alternatively, you could have custom html helpers embedded within the main view that ran approprite code when the view was refreshed.

As for multiple views from a single action, i don't think this is both a good idea or in any way possible.

of course, rules are there to be broken :)


I don't think there is any automatic way to do this, but you could use some convention and:

  • Create a custom view result that takes in multiple partial view results i.e. a MultiplePartialViewResult
  • In the execute of the custom view result, call each the execute method of each of the supplied views'. Make sure to wrap each in a div or some other container for ease of retrieval at the client script
  • Upon receiving the response on the AJAX call in the client script, grab the value from each container and replace it in the corresponding elements matching the partial views initially rendered

For the last step you could use a convention. A simple one would be (if there is only one instance for each partial view) to put the id of target html element to update in the div/container you used to wrap it in the second step.


Based on what you're saying, I think using javascript and ajax to refresh from the server would be best.

You could use Html.RenderPartialAction to achieve DRY by putting it on the page, and then loading it using ajax and javascript.

If you were using jQuery, then something like this would work:

jQuery("#divToReload1").load('Url/To/PartialAction')...
jQuery("#divToReload2").load('Url/To/PartialAction')...

Just put that all inside one function and you'll reload all your partials at once.

You can send data through using the data parameter and catch the callback function to do as you wish.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜