找不到路径控制器...或未实现IController [英] The controller for path ... was not found or does not implement IController
问题描述
我正在使用c#使用ASP.NET MVC 5编写应用程序.我需要在应用程序的右上角添加一个全局菜单.我被告知 然后我像这样从 要在布局中渲染 现在,当我运行我的应用程序时,出现以下错误 当我从布局中删除 我该怎么做才能解决此问题? 已更新
这是我从下面的评论中获得反馈后所做的事情 但仍然是相同的错误 从 在您的示例中,您没有 Phil Haacked-Html.RenderAction和Html.Action 由另一篇文章链接的文章为您提供了一个很好的例子. I am writing an application using ASP.NET MVC 5 using c#. I have a need to add a global menu on the upper right hand side of the application. I was advised other SO to use action with So here is what I have done. I created a BaseController like this Then I inherited all my controllers from To render the Now when I run my application I get the following error When I remove What can I do to resolve this issue? Updated
Here is what I have done after the feedback I got from the comments below but still the same error Take In your example you don't have a The Phil Haacked - Html.RenderAction and Html.Action article linked to by the other post provided a good example for you to follow. 这篇关于找不到路径控制器...或未实现IController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!BaseController
继承了我的所有控制器public class TasksController : BaseController
{
public ActionResult Index(int ClientId)
{
...
return View();
}
public ActionResult Show(int SurveyId)
{
...
return View();
}
}
ClientsMenu
,我添加了以下代码@Html.Action("ClientsMenu", "Menus")
The controller for path '/Tasks/Index' was not found or does not implement IController.
@Html.Action("ClientsMenu", "Menus")
时,一切正常,但是全局菜单当然不会显示.public class TasksController : Controller
{
[ChildActionOnly]
public ActionResult ClientsMenu()
{
using (SomeContext db = new SomeContext())
{
return PartialView(db.Database.SqlQuery<Client>("SELECT * FROM clients").ToList());
}
}
public ActionResult Index(int ClientId)
{
...
return View();
}
public ActionResult Show(int SurveyId)
{
...
return View();
}
}
BaseController
中取出ClientMenus
动作,并将其放入其自己的控制器MenusController
中.然后,您可以从视图中调用该控制器.@Html.Action("ClientsMenu", "Menus")
MenusContoller
,而这正是@Html.Action("ClientsMenu", "Menus")
所要查找的. p>
ChildActionOnly
attribute.public class BaseController : Controller
{
[ChildActionOnly]
public ActionResult ClientsMenu()
{
using (SomeContext db = new SomeContext())
{
return PartialView(db.Database.SqlQuery<Client>("SELECT * FROM clients").ToList());
}
}
}
BaseController
like sopublic class TasksController : BaseController
{
public ActionResult Index(int ClientId)
{
...
return View();
}
public ActionResult Show(int SurveyId)
{
...
return View();
}
}
ClientsMenu
in my layout I added the following code@Html.Action("ClientsMenu", "Menus")
The controller for path '/Tasks/Index' was not found or does not implement IController.
@Html.Action("ClientsMenu", "Menus")
from the layout everything works fine but the global menu does not show of course.public class TasksController : Controller
{
[ChildActionOnly]
public ActionResult ClientsMenu()
{
using (SomeContext db = new SomeContext())
{
return PartialView(db.Database.SqlQuery<Client>("SELECT * FROM clients").ToList());
}
}
public ActionResult Index(int ClientId)
{
...
return View();
}
public ActionResult Show(int SurveyId)
{
...
return View();
}
}
ClientMenus
Action out of the BaseController
and put it into its own controller MenusController
. You can then call that controller from your Views.@Html.Action("ClientsMenu", "Menus")
MenusContoller
which is what @Html.Action("ClientsMenu", "Menus")
is looking for.