Search code examples
razorintellisenserazorengine

RazorEngine 3.2.0: Razor Namespace not found in .cshtml File


I'm using RazorEngine 3.2.0 in a Class Library project.

I resolved some Class Library related issues by following the following answer to the following SO-question: Razor intellisense error: Feature 'extension method' cannot be used because it is not part of the ISO-2 C# language specification

Problem

I try to use the @inherits keyword. If I just write the full qualified name for the view-class, intellisense works. If I try to inherit from RazorEngine.Templating.TemplateBase<T> it seems that the whole RazorEngine-Assemlby isn't resolved.

The Template looks like this:

@inherits RazorEngine.Templating.TemplateBase<ViewModels.PrintCatalogData>
<!DOCTYPE html>
<html>
<head>
...

At Runtime it works - just intellisense is failing.

Question

What is needed that the intellisense recognizes the RazorEngine-Assembly?


Solution

  • The @inherits probably does not like the fully qualified name. Try adding the namespace RazorEngine.Templating to your web.config and then remove the fully qualified name from the view template.

      <system.web.webPages.razor>
         <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc,    Version=4.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.Optimization"/>
              <add namespace="System.Web.Routing" />
              <add namespace="Assemblies"/>
              <add namespace="RazorEngine.Templating"/>
              <add namespace="Resources"/>
            </namespaces>
         </pages>