ASP.NET MVC3 Razor - 将视图放置在备用位置时丢失智能感知?
VS2010 Ultimate、ASP.NET MVC 3 带 Razor。
我在我的 MVC3 应用程序中创建了一个自定义视图引擎,允许嵌套区域,例如
~/areas/admin
/marketing
/views
index
/controllers
marketingController
/email
/views
index
...
/controllers
emailController
/templates
/views
index
edit
...
/controllers
templatesControler
等。
这一切都很好,除了我似乎在不在标准 ~/areas/ 中的视图中丢失了智能感知。 area_name/views/myview.cshtml
位置。
有什么建议吗?
更新
只是一时兴起,我添加了一条 @inherits 语句
@inherits System.Web.Mvc.WebViewPage<Namespace.Models.Class>
,然后智能感知开始工作。然后我删除了该语句,它继续工作。
除了文件扩展名之外,项目文件中是否有某些设置或告诉 Visual Studio 对打开的文件应用哪种智能感知的设置? (如果仅使用扩展名,我希望它会更加一致)。
更新 2
虽然将 web.config 添加到我的每个视图文件夹可以很好地解决问题,但将 razor 配置放在根 web.config 中却不能。
将所需的 system.web.webPages.razor
部分添加到 ~/web.config
后,
- 我将 Razor .cshtml 视图文件添加到我的嵌套视图文件夹之一。
- 智能感知有效。
- 我重命名该文件(保留 .cshtml 扩展名)
- 智能感知和语法突出显示停止工作。
- 我关闭重命名的文件并重新打开它 - 一切都重新开始工作。
- 或者,我没有关闭并重新打开文件,而是将其重命名回原来的名称,它再次开始工作。
这感觉就像一个 VS bug——据我所知,重命名文件(但保留正确的扩展名)不应该导致这种行为。我将继续将单独的 web.config
放入每个视图文件夹中,因为它可以解决问题,但是当我希望这些设置通过解决方案树与其他 web.config 设置一样。
还值得注意的是,无论 Razor 配置位于何处,无论智能感知是否正常工作,该站点都会继续正常运行。
已解决
权力机构通知我(速度非常快),这是一个已知问题,已在 MVC3 RTM 和 VS2010 SP1 中得到纠正。更新我的 MVC3 安装并添加 SP1 后,该问题消失了。
VS2010 Ultimate, ASP.NET MVC 3 w/Razor.
I've created a custom view engine in my MVC3 app that allows nested areas, like so
~/areas/admin
/marketing
/views
index
/controllers
marketingController
/email
/views
index
...
/controllers
emailController
/templates
/views
index
edit
...
/controllers
templatesControler
etc.
This all works great, except for I seem to have lost intellisense in views that aren't in the standard ~/areas/area_name/views/myview.cshtml
location.
Any suggestions?
Update
Just on a lark, I added an @inherits statement
@inherits System.Web.Mvc.WebViewPage<Namespace.Models.Class>
and intellisense started working. I then deleted the statement, and it continues to work.
Is there some setting in the project file or something that tells Visual Studio what sort of intellisense to apply to an open file, other than the file extension? (If the extension was all that was used, I'd expect it to be a whole lot more consistent).
Update 2
While adding a web.config to each of my view folders fixes the problem quite nicely, putting the razor config in the root web.config doesn't.
After adding the required system.web.webPages.razor
section to ~/web.config
,
- I add a Razor .cshtml view file to one of my nested view folders.
- Intellisense works.
- I rename the file (keeping the .cshtml extension)
- Intellesense and syntax highlighting stop working.
- I close the renamed file and reopen it - everything starts working again.
- Or, instead of closing and reopening the file, I rename it back to its original name, it starts working again.
This feels like a VS bug - renaming a file (but keeping the proper extension) shouldn't, as far as I can tell, cause this sort of behavior. I'll continue putting individual web.config
s in each of my view folders since it corrects the problem, but it's annoying to have to clutter up the solution when I'd expect these settings to propagate through the solution tree as other web.config settings do.
It's also worth noting that, no matter where the Razor config is located, the site continues to function correctly whether or not intellesense is working.
Solved
I was informed (incredibly quickly) by the Powers That Be that this was a known issue that is corrected in MVC3 RTM and VS2010 SP1. The issue disappeared after updating my MVC3 installation and adding SP1.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Views 文件夹包含 Web.config 文件它为 Razor 视图设置默认选项,包括默认的基本类型和命名空间,以及启用
@model
指令的自定义主机。不同文件夹中的 Razor 视图不会继承此配置。
您需要将此配置添加到文件夹中的
Web.config
中:The Views folder contains a Web.config file that sets default options for Razor views, including the default base type and namespaces, as well as a custom host that enables the
@model
directive.Razor views in a different folder won't inherit this configuration.
You need to add this configuration to a
Web.config
in your folder: