Hao
Hao

Reputation: 8115

Can I make razor recognize .html file extension as its own?

So I can use the designer mode? I'm relying less on asp.net mvc html helpers, but not totally ditching it, opting to use plain html (in which should have no problem being rendered in Design Mode) instead

Is this possible?

Upvotes: 2

Views: 524

Answers (1)

Betty
Betty

Reputation: 9189

Write you own View Engine

public class MyRazorViewEngine : RazorViewEngine 
{
    public MyRazorViewEngine() 
{
        base.AreaViewLocationFormats = new string[]
    {
    "~/Areas/{2}/Views/{1}/{0}.html", 
    "~/Areas/{2}/Views/Shared/{0}.html", 
        };
 ....

See System.Web.Mvc.RazorViewEngine for the rest of the locations to include

Then register it on startup

ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new MyRazorViewEngine()));
    RazorCodeLanguage.Languages["html"] = new CSharpRazorCodeLanguage();

and the following to your applications web.config

<system.web>    
  <compilation debug="true" targetFramework="4.5" >
    <assemblies>
      <add assembly="System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    </assemblies>
    <buildProviders>
      <add extension=".html"          type="System.Web.WebPages.Razor.RazorBuildProvider, System.Web.WebPages.Razor"/>
    </buildProviders>
  </compilation>
</system.web>

Upside - you get designer mode, Downside - you lose all razor highlighting and intellisense

Upvotes: 2

Related Questions