Browse Source

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

pull/29/head
Teknikode 7 years ago
parent
commit
bd6d71de46
  1. 51
      Teknik/App_Start/CustomRazorViewEngine.cs
  2. 3
      Teknik/Global.asax.cs
  3. 1
      Teknik/Teknik.csproj

51
Teknik/App_Start/CustomRazorViewEngine.cs

@ -0,0 +1,51 @@ @@ -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
Teknik/Global.asax.cs

@ -21,6 +21,9 @@ namespace Teknik @@ -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
Teknik/Teknik.csproj

@ -137,6 +137,7 @@ @@ -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