Wednesday 25 July 2012

Asp.Net MVC partial view controller action

While you can have an action that returns a partial view, you don't need an action to render a partial view. RenderPartial takes the partial view and renders it, using the given model and view data if supplied, into the current (parent) view.
Html.RenderPartial( "Partial");
You might want an action that returns a partial view if you are using AJAX to load/reload part of a page. In that case, returning the full view is not desired since you only want to reload part of the page. In this case you can have the action just return the partial view that corresponds to that section of the page.

public ActionResult Action(...)
{ 
    return PartialView( "Partial");
}

No comments:

Post a Comment