2

我有一个剃须刀母版页 (_Layout.cshtml),我在其中布局了一个 3 列网站。在其中一个侧栏中,我想显示“登录控件”

根据我的阅读,我可以使用 Html.RenderAction 来调用我的 LoginController,它会在侧栏中显示登录视图。

但是,当我运行它并将其指向控制器/视图以填充 RenderBody() 时,对 Html.RenderAction("Index", "LoginController") 的调用失败并出现此错误。

 "The controller for path '/[insert path to a Controller/View to fill the 
  RenderBody()]' was not found or does not implement IController. "

那么,我做错了什么?

我的代码真的很简单:

    <div id="Navigation">@{ Html.RenderPartial("Test"); }</div>
    <div id="Main">@RenderBody()</div> 
    <div id="Misc">@{ Html.RenderAction("Index", "LoginController");}</div>

在我的控制器文件夹中,我有 RenderBody 和 LoginController 的控制器。

4

1 回答 1

9

在 MVC 中按约定指定控制器名称时,不包括“控制器”部分。

Html.RenderAction("Index", "LoginController")

除非您有一个名为“LoginControllerController”的控制器,否则它将无法工作

尝试

<div id="Misc">@{ Html.RenderAction("Index", "Login");}</div>
于 2012-05-02T18:36:39.323 回答