Browse Source

Added custom razor engine to limit the view engine lookup to just c#

tags/2.0.3
Teknikode 4 years ago
parent
commit
bd6d71de46
3 changed files with 55 additions and 0 deletions
  1. 51
    0
      Teknik/App_Start/CustomRazorViewEngine.cs
  2. 3
    0
      Teknik/Global.asax.cs
  3. 1
    0
      Teknik/Teknik.csproj

+ 51
- 0
Teknik/App_Start/CustomRazorViewEngine.cs View File

@@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;

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

base.AreaMasterLocationFormats = new string[]
{
"~/Areas/{2}/Views/{1}/{0}.cshtml",
"~/Areas/{2}/Views/Shared/{0}.cshtml"
};

base.AreaPartialViewLocationFormats = new string[]
{
"~/Areas/{2}/Views/{1}/{0}.cshtml",
"~/Areas/{2}/Views/Shared/{0}.cshtml"
};

base.ViewLocationFormats = new string[]
{
"~/Views/{1}/{0}.cshtml",
"~/Views/Shared/{0}.cshtml"
};

base.PartialViewLocationFormats = new string[]
{
"~/Views/{1}/{0}.cshtml",
"~/Views/Shared/{0}.cshtml"
};

base.MasterLocationFormats = new string[]
{
"~/Views/{1}/{0}.cshtml",
"~/Views/Shared/{0}.cshtml"
};
}
}
}

+ 3
- 0
Teknik/Global.asax.cs View File

@@ -21,6 +21,9 @@ namespace Teknik
{
protected void Application_Start()
{
ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new CustomRazorViewEngine());

Database.SetInitializer(new MigrateDatabaseToLatestVersion<TeknikEntities, Migrations.Configuration>());

AreaRegistration.RegisterAllAreas();

+ 1
- 0
Teknik/Teknik.csproj View File

@@ -137,6 +137,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="App_Start\BundleConfig.cs" />
<Compile Include="App_Start\CustomRazorViewEngine.cs" />
<Compile Include="App_Start\FilterConfig.cs" />
<Compile Include="App_Start\RouteConfig.cs" />
<Compile Include="Areas\About\AboutAreaRegistration.cs" />

Loading…
Cancel
Save