【发布时间】:2017-11-18 05:04:05
【问题描述】:
我需要一个带有菜单的 _LayoutPage,该菜单基于我从服务器读取的用户权限。
我找到this的文章并尝试实现它
基本上布局调用一个动作到控制器搜索用户权限并返回一个部分视图,只呈现它的一些元素
这是 _Layout 正文:
<body>
@Html.Action("RenderMenu", "MasterController")
<div id="bodyMasterPage">
@RenderBody();
</div>
<div id="footerMasterPage">
</div>
</body>
intestazione是我的部分观点,暂时还很空
主控制器:
public class MasterController : Controller
{
public ActionResult RenderMenu()
{
{
return PartialView("Instestazione", null);
}
}
}
和测试控制器
public class TestController : Controller
{
public IUnitOfWork myUow;
// GET: WebMVC/Test
public TestController(IUnitOfWork uow)
{
myUow = uow;
}
public ActionResult Index()
{
myUow.Area.Read(1);
return View();
}
}
现在当我打开http://localhost:61599/WebMVC/Test/Index 得到这个错误:
The controller for path '/WebMVC/Test/Index' was not found or does not implement IController.
Descrizione: Eccezione non gestita durante l'esecuzione della richiesta Web corrente. Per ulteriori informazioni sull'errore e sul suo punto di origine nel codice, vedere la traccia dello stack.
Dettagli eccezione: System.Web.HttpException: The controller for path '/WebMVC/Test/Index' was not found or does not implement IController.
Errore nel codice sorgente:
Riga 16: </head>
Riga 17: <body>
Riga 18: @Html.Action("RenderMenu", "MasterController")
Riga 19: <div id="bodyMasterPage">
Riga 20: @RenderBody();
自从谈到 TestController 之后这似乎很奇怪,如果我删除 Html.Action 代码 (@Html.Action("RenderMenu", "MasterController")) alla 工作正常
为什么在 TestController 上调用 MasterController 会出错
【问题讨论】:
标签: asp.net asp.net-mvc asp.net-mvc-routing