I am trying to create a RenderAction method on the main page that will dynamically generate a sidebar based on the current controller and action. When a RenderAction is called in a view, it is populated by the controller and the action of this particular RenderAction method. For example, if I am on the Home controller and the Index action, I expect the Home and Index in the GenerateSideBar method. Instead, I get a Home controller and a RenderSideBar action. Thank you for your help!
My main page:
<div class="side-bucket">
<%
string Controller = ViewContext.RouteData.Values["Controller"].ToString();
string Action = ViewContext.RouteData.Values["Action"].ToString();
%>
<% Html.RenderAction("RenderSideBar", "Home", new { controller = Controller, action = Action }); %>
Controller action:
public ActionResult GenerateSideBar(string controller, string action)
{
switch (controller.Trim().ToLower())
{
case "member" :
return View(@"sidebar\MemberSidebar");
default:
break;
}
return null;
}
source
share