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
,
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.
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:
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
</namespaces>
</pages>
</system.web.webPages.razor>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With