【问题标题】:Html.Action within _SharedLayout to partialView with controller共享布局中的 Html.Action 到带有控制器的部分视图
【发布时间】: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


    【解决方案1】:

    您是否尝试过添加区域?

    @Html.Action("RenderMenu", "MasterControler", new {area=""})
    

    在这里找到: The controller for path was not found or does not implement IController

    【讨论】:

      【解决方案2】:

      问题在这里:@Html.Action("RenderMenu", "MasterControler")

      Controller后缀不得使用

      我从链接中获取代码而没有太多关注

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-02-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-05-29
        相关资源
        最近更新 更多