如何从 MVC 3 中的某个区域渲染主项目中的部分内容?
我有一个 MVC 3 Razor 项目。它有一个名为“管理”的区域。我在项目的 Views/Shared 文件夹中拥有页面的基本布局(默认情况下)。我在主项目中有一个名为 Common 的控制器。它将负责基于业务逻辑的布局的某些部分(基于角色的导航等)。我
@Html.Action("Navigation", "Common")
在 _layout.cshtml 文件中调用了 。设置为渲染导航栏。当我转到管理区域中的路线(“admin/somedomainobject/add”)时,运行时错误指出以下内容:
“路径控制器 “/admin/somedomainobject/add”不是 发现或未实施 我控制器。”
当我从布局中删除该行时,它存在得很好。如果我使用上述语法或以下语法,就会发生错误:
@{Html.RenderAction("Naviation", "Common");}
因为我正在使用区域吗?我是否以错误的方式使用主项目文件夹?
任何想法将不胜感激!
I have a MVC 3 Razor project. It has an area called Admin. I have the basic layout of the page in the project's Views/Shared folder (by default). I have a controller in the main project called Common. It will be in charge of certain parts of the layout that are based on business logic (navigation based upon roles, etc.). I have
@Html.Action("Navigation", "Common")
being called in the _layout.cshtml file. That is set to render the nav bar. When I go to a route in the Admin area ("admin/somedomainobject/add"), a run time error states the following:
"The controller for path
"/admin/somedomainobject/add" was not
found or does not implement
IController."
It exists just fine, when I remove the line from the layout. The error is happening if I use the above syntax or the following:
@{Html.RenderAction("Naviation", "Common");}
Is it because I am using areas? Am I utilizing the main project folders the wrong way?
Any ideas would be greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为在您的管理区域中,除非明确告知,否则所有生成的链接都将继承该区域,请尝试
It is because in your admin area all generated links will inherit this area unless explicitly told otherwise, try