Html.Action 在共享布局中使用控制器进行局部视图
Html.Action within _SharedLayout to partialView with controller
我需要一个带有菜单的 _LayoutPage,它基于我从服务器读取的用户权限。
我找到 this 文章并尝试实现它
基本上,Layout 会调用一个操作来搜索用户权限的控制器和 return 只呈现部分元素的局部视图
这是结构:
这个_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 工作正常
为什么调用 MasterController 在 TestController 上出错
您试过添加区域吗?
@Html.Action("RenderMenu", "MasterControler", new {area=""})
在此处找到:
The controller for path was not found or does not implement IController
问题在这里:@Html.Action("RenderMenu", "MasterControler")
Controller
后缀不必使用
我从link那里拿了代码,但没怎么注意
我需要一个带有菜单的 _LayoutPage,它基于我从服务器读取的用户权限。
我找到 this 文章并尝试实现它
基本上,Layout 会调用一个操作来搜索用户权限的控制器和 return 只呈现部分元素的局部视图
这是结构:
这个_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 工作正常
为什么调用 MasterController 在 TestController 上出错
您试过添加区域吗?
@Html.Action("RenderMenu", "MasterControler", new {area=""})
在此处找到: The controller for path was not found or does not implement IController
问题在这里:@Html.Action("RenderMenu", "MasterControler")
Controller
后缀不必使用
我从link那里拿了代码,但没怎么注意