Reputation: 23093
I am creating a CMS using MVC 4 and the Razor Syntax and have a strange problem.
In the main project everything is working fine, but I have some additional projects in the solution (also MVC 4 projects) which are extensions to the main project (loaded at runtime) which also have their own views/layouts.
Now in these additional projects the razor editor does eighter highlight as it should, but underlining everything as missing (like the Html helper) or it does not work at all:
or
Does anyone have an idea why? The files are open with the Razor editor via "Open With..." to be shure the Razor editor is used.
Upvotes: 1
Views: 1347
Reputation: 1038710
You just have to add a dummy web.config
file to the root of your class library with the following contents in order to fool Visual Studio's Intellisense in Razor files (taken from this blog post
):
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>
</configSections>
<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>
<system.web>
<compilation targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</assemblies>
</compilation>
</system.web>
</configuration>
Upvotes: 1
Reputation: 23093
I found the problem:
I configured the build to directly build to the plugin folder of my Main Project for easy debugging and it seems the razor editor does not like that. As soon as I set the output back to "bin\" it works again.
I will now create post build steps to do the copy...
Upvotes: 1
Reputation: 2596
Ive done a similar thing using MEF to create plug ins. Make sure you add a using statememnt for 'system.web.mvc' and 'system.web.mvc.html'
Think there the right ones... Not got solution to check
Here you go:
@using System.Web.Mvc.Html;
@using System.Web.Mvc;
@model Terminals.Models.vmDeviceAdd
@{
ViewBag.Title = "Index";
Layout = "~/Areas/Terminals/Views/Shared/Master/_TerminalLayout.cshtml";
}
Upvotes: 0