Html.RenderPartial call from masterpage Html.RenderPartial call from masterpage asp.net asp.net

Html.RenderPartial call from masterpage


How about creating an HtmlHelper extension method that allows you to call a partial view result on the an action on the controller.

Something like

 public static void RenderPartialAction<TController>(this HtmlHelper helper, Func<TController, PartialViewResult> actionToRender)    where TController : Controller, new(){    var arg = new TController {ControllerContext = helper.ViewContext.Controller.ControllerContext};    actionToRender(arg).ExecuteResult(arg.ControllerContext);} 

you could then use this in your master page like

<% Html.RenderPartialAction((HomeController x) => x.RenderPartial()) %>

and in your controller the appropriate method

public PartialViewResult RenderPartial(){     return PartialView("~/Path/or/View",_homeService.GetModel())}

Well that is my 2 cents anyway


I had a similar post and came up with an object model to handle it.

I HATE the non-strongly typed views so went with this approach and it is working well.


I think that your solution may lie in the land of MVC 2.0 RC and beyond...

Phil Haack posted an article on his blog: http://haacked.com/archive/2009/11/18/aspnetmvc2-render-action.aspx