使用多个项目的 ASP.NET MVC 区域应用程序
我一直在关注本教程:
并有一个像这样设置的应用程序(稍微复杂一点)。所有区域都工作正常,但是我注意到,如果我将帐户项目的项目名称更改为 Areas.Accounts,则由于区域名称与帐户项目不同,它不会在帐户项目中找到我的任何视图项目名称,例如账户的routes.cs 文件仍然有这个:
public override string AreaName
{
get { return "Accounts"; }
}
有谁知道为什么我必须将其更改为:
public override string AreaName
{
// Needs to match the project name?
get { return "Areas.Accounts"; }
}
为了让我在账户项目中的视图正常工作?
我真的希望 AreaName 仍然是 Accounts,但是当 ASP.net MVC 全部合并到一个项目中时,请在“Views\Areas\Areas.Accounts\”文件夹中查找,而不是尝试在“View\区域\帐户\"
谢谢 标记
I have been following this tutorial:
and have an application (a bit more complex) like this set up. All the areas are working fine, however I have noticed that if I change the project name of the Accounts project to say Areas.Accounts, that it wont find any of my views within the accounts project due to the Area name not being the same as the project name e.g. the accounts routes.cs file still has this:
public override string AreaName
{
get { return "Accounts"; }
}
Does anyone know why I would have to change it to this:
public override string AreaName
{
// Needs to match the project name?
get { return "Areas.Accounts"; }
}
for my views in the accounts project to work?
I would really like the AreaName to still be Accounts, but for ASP.net MVC to look in the "Views\Areas\Areas.Accounts\" folder when its all munged into one project, rather than trying to find it within "View\Areas\Accounts\"
Thanks
Mark
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我离得还很远,请原谅我,我最近才开始接触 MVC 2.0(当我被拉去从事其他事情时,我并没有与 MVC 1.0 走得太远)...
我有一种感觉您的代码中会自动连接,当您更改项目名称时,无论连接做什么都不会检测/理解更改。我假设在某个地方路由查找没有建立连接,因此您被迫使用详细名称。只是基于有多少软件包的存在似乎只是为了处理连接事件、操作和其他所有内容。
Forgive me if I'm way off, I've only recently started into MVC 2.0 (and I wasn't that far along with MVC 1.0 when I was pulled away to work on something else)...
I have the feeling that something in your code is auto-wiring for you, and when you changed the project name, whatever did the wiring isn't detecting/understanding the change. I assume somewhere the route look-up just isn't making the connection so you're forced to use the verbose name. Just a thought based on how many packages out there seem to exist just to handle wiring up events, actions, and everything else.