Guest User

Untitled

a guest
Apr 27th, 2016
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.67 KB | None | 0 0
  1. namespace STDotCom
  2. {
  3.     using System;
  4.     using System.Web.Mvc;
  5.  
  6.     /// <summary>
  7.     ///  Used to make razor aware of where views are located on a module by module basis.
  8.     /// </summary>
  9.     public class WidgetFolderViewEngine : VirtualPathProviderViewEngine
  10.     {
  11.         /// <summary>
  12.         ///  Initializes a new instance of the <see cref="WidgetFolderViewEngine"/> class.
  13.         /// </summary>
  14.         public WidgetFolderViewEngine()
  15.         {
  16.             string[] widgetFolderFormats = new[]
  17.             {
  18.                 "~/Widgets/{1}/Views/{0}.cshtml"
  19.             };
  20.  
  21.             this.FileExtensions = new string[] { "cshtml", "vbhtml", "aspx", "ascx" };
  22.             this.AreaViewLocationFormats = widgetFolderFormats;
  23.             this.AreaMasterLocationFormats = widgetFolderFormats;
  24.             this.AreaPartialViewLocationFormats = widgetFolderFormats;
  25.             this.ViewLocationFormats = widgetFolderFormats;
  26.             this.MasterLocationFormats = widgetFolderFormats;
  27.             this.PartialViewLocationFormats = widgetFolderFormats;
  28.         }
  29.  
  30.         public override ViewEngineResult FindPartialView(ControllerContext controllerContext, string partialViewName, bool useCache)
  31.         {
  32.             return base.FindPartialView(controllerContext, partialViewName, useCache);
  33.         }
  34.  
  35.         public override ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache)
  36.         {
  37.             return base.FindView(controllerContext, viewName, masterName, useCache);
  38.         }
  39.  
  40.         protected override bool FileExists(ControllerContext controllerContext, string virtualPath)
  41.         {
  42.             return base.FileExists(controllerContext, virtualPath);
  43.         }
  44.  
  45.         protected override IView CreatePartialView(ControllerContext controllerContext, string partialPath)
  46.         {
  47.             if (partialPath.EndsWith(".cshtml") || partialPath.EndsWith(".vbhtml"))
  48.             {
  49.                 return new RazorView(controllerContext, partialPath, null, false, null);
  50.             }
  51.             else
  52.             {
  53.                 return new WebFormView(controllerContext, partialPath);
  54.             }
  55.         }
  56.  
  57.         protected override IView CreateView(ControllerContext controllerContext, string viewPath, string masterPath)
  58.         {
  59.             if (viewPath.EndsWith(".cshtml") || viewPath.EndsWith(".vbhtml"))
  60.             {
  61.                 return new RazorView(controllerContext, viewPath, masterPath, false, null);
  62.             }
  63.             else
  64.             {
  65.                 return new WebFormView(controllerContext, viewPath, masterPath);
  66.             }
  67.         }
  68.     }
  69. }
Add Comment
Please, Sign In to add comment