Another option is to use a method RenderActionthat will trigger an action (either on the current controller or on delivery the name of the controller, as well as this controller), which can then create menu data for you and invoke a partial ascx view:
So, on my main page, I can:
<% Html.RenderAction("MenuArchiveList"); %>
Then in my controller:
public ActionResult MenuArchiveList() {
return PartialView("BlogArchiveList",
_BlogRepository.GetArchiveYearPostCounts());
}
Then successfully finds user control \Views\Shared\BlogArchiveList.ascx
If you want your action to be invoked only in the context of a partial view, you should decorate it with ChildActionOnlyAttribute.
This was added to System.Web.Mvc in version 2 of the Microsoft.Web.Mvc Futures namespace.
source
share