我想使用RenderAction在布局中创建一个动态菜单。 我做了一个动态菜单,因为每个登录的用户都有一个不同的菜单。 我要做的是为菜单创建一个视图(DashboardSideMenu),然后使用 @ {Html.RenderAction();} 在布局中调用该视图。 错误是
System.Web.HttpException:'对处理程序'System.Web.Mvc.HttpHandlerUtil + ServerExecuteHttpHandlerAsyncWrapper执行子请求时出错。'
下面是我的代码,谢谢。
//User Controller
[ValidateUserRolesAuthorization]
public ActionResult DashboardSideMenu()
{
if (Session["Username"] != null)
{
foreach (var eachMenu in menusAssigned)
{
if (eachMenu.MenuName == "Form Role Manager")
{
menuAccessViewModel.IsGrantedFormRoleManager = true;
}
else if (eachMenu.MenuName == "Form Registrasi User")
{
menuAccessViewModel.IsGrantedFormRegistrasiUser = true;
}
}
}
return PartialView(menuAccessViewModel);
}
DashboardSideMenu视图
@model BCAF_EPayment.Data.ViewModels.MenuAccessViewModel
<section class="sidebar">
@if (Model.IsGrantedFormRoleManager == true)
{
@Html.ActionLink("Form Role Manager", "Index", "RoleManager", null, new { @class = "btn btn-primary" })
}
@if (Model.IsGrantedFormRegistrasiUser == true)
{
@Html.ActionLink("Form Registrasi User", "Index", "RegistrasiUser", null, new { @class = "btn btn-primary" })
}
</section>
布局
<header class="main-header">
<nav class="navbar navbar-static-top">
<span class="hidden-xs">Hello, @HttpContext.Current.Session["UserFullName"]</span>
<nav>
</header>
<aside class="main-sidebar">
@{Html.RenderAction("DashboardSideMenu", "User");} //the error is here
</aside>