开发者

How to Refresh Base View from Partial View Action

I'm new to MVC, and I'm implementing a web app with lot of AJAX and partial views.

I have 2 views: 1 base view and 1 partial view. Each view has its own controller. The b开发者_StackOverflow社区ase view send data to the partial view via Model.

I'd like to make the partial view/controller send data to the base view/controller. What is the best way to do that? Is there a way to refresh the base view from a partial view action?

        public ActionResult SendDataToBaseView()
        {
            return View("BaseView", viewModel);
        }


It's not quite clear what your setup is.

If you're updating HTML that was rendered from the main view, then you'll likely have another controller action on the same controller on which you called an action to render the base view. This other controller action may return JSON or HTML (as a Partial View perhaps) and it will be your responsibility on the client side to take the result of the AJAX call and populate the sections of the page that were rendered by the base view with this new data.

Here are the steps that I would envisage being taken

  1. Controller action called to render base view. Let's call the controller BaseController and the action Index
  2. Inside the base view a call is made to render a partiaol view, via Html.RenderPartial(), Html.RenderAction() or Html.Action()
  3. Response is sent to client
  4. Event happens on client requiring update to data rendered by base view.
  5. AJAX request is made to BaseController Update action that returns a JsonResult containing data that can be used to updates parts of the response outputted by the base view.
  6. Receive response on client side and update those parts of the DOM.
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜