路径控制器未找到或未实现 IController [英] The controller for path was not found or does not implement IController

查看:119
本文介绍了路径控制器未找到或未实现 IController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有语言选择的 MVC4 项目:

I have an MVC4 project with language selection:

  • zh
  • nl
  • fr

1 个主要部分:

  • 关于
  • 通用(用于菜单)
  • 联系方式
  • 常见问题
  • 首页

还有 3 个区域:

  • 管理员
  • 客户
  • 购物

在每个区域我至少有一个控制器,例如在管理我有控制器 overview 和相应的视图文件夹 overview,其中包含一个 index.html.aspx 页面.

In each area I have at least one controller, for example in Admin I have the controller overview with the corresponding view folder overview which contains an index.aspx page.

主页和所有主要页面(关于、常见问题等)都有效并且可以访问.

The home page and all the main pages (about, faq, etc.) work and can be visited).

但是,当我按照 url: localhost:xxxx/en/admin/overview我收到错误:

However, when I follow the url: localhost:xxxx/en/admin/overview I get the error:

路径/en/admin/overview"的控制器未找到或未实现 IController.

The controller for path '/en/admin/overview' was not found or does not implement IController.

即使路由是正确的(我可以用路由调试器看到这一点),错误页面也显示当我想加载我的主菜单项时抛出了错误:

Even though the route is correct (I can see this with Route Debugger), the error page also shows that the error was thrown when I wanted to load my main menu items:

<nav id="site-navigation" class="eightcol">
    @Html.Action("MenuItems", "Common")
</nav>

-- 代码因为不相关而被删除 --

似乎一切正常,但 MVC 似乎无法加载位于主要部分的菜单.

Everything seems to be in order, but MVC doesn't seem to be able to load the menu, which is located in the main part.

所以,问题的根源在于:我可以授予某个区域(例如管理员)访问我项目主要部分(主页、公共、关于等)中的控制器的权限吗?

So, the root of the problem is: Can I grant an area (e.g. Admin) access to the controllers in the main part (home, common, about, etc.) of my project?

推荐答案

我找到了.

当位于区域内的页面想要访问位于该区域外的控制器(例如共享布局页面或不同区域内的某个页面)时,该控制器的区域需要访问添加.由于公共控制器不在特定区域而是主项目的一部分,因此您必须将区域留空:

When a page, that is located inside an area, wants to access a controller that is located outside of this area (such as a shared layout page or a certain page inside a different area), the area of this controller needs to be added. Since the common controller is not in a specific area but part of the main project, you have to leave area empty:

@Html.Action("MenuItems", "Common", new {area="" }) 

由于布局页面在各个区域共享,因此需要将上述内容添加到所有操作和操作链接中.

The above needs to be added to all of the actions and actionlinks since the layout page is shared throughout the various areas.

这和这里的问题完全一样:具有共享布局的 ASP.NET MVC 区域

It's exactly the same problem as here: ASP.NET MVC Areas with shared layout

编辑:明确地说,这被标记为答案,因为它是我的问题的答案.以上答案可能会解决触发相同错误的原因.

Edit: To be clear, this is marked as the answer because it was the answer for my problem. The above answers might solve the causes that trigger the same error.

这篇关于路径控制器未找到或未实现 IController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆