_SharedLayout中的Html.Action到带控制器的partialView

时间:2017-06-15 15:54:58

标签: asp.net asp.net-mvc asp.net-mvc-routing

我需要一个带有menù的_LayoutPage,基于我从服务器读取的用户权限。

我找到this文章并尝试实施

基本上布局调用一个动作来控制器搜索用户权限并返回一个部分视图,只渲染其中一些元素

这是结构: structure

这是_ Layout正文:

<body>  
    @Html.Action("RenderMenu", "MasterController")
    <div id="bodyMasterPage">
        @RenderBody();

    </div>
    <div id="footerMasterPage">

    </div>
</body>

intestazione是我的部分观点,现在很空白

MasterController:

public class MasterController : Controller
    {
        public ActionResult RenderMenu()
        {           
            {
                return PartialView("Instestazione", null);
            }
        }
    }

和TestController

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上获得错误

2 个答案:

答案 0 :(得分:0)

您是否尝试过添加该区域?

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

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

答案 1 :(得分:0)

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

Controller后缀不得使用

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