Advertisement
Guest User

Untitled

a guest
Apr 27th, 2016
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.99 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.         protected override IView CreatePartialView(ControllerContext controllerContext, string partialPath)
  31.         {
  32.             if (partialPath.EndsWith(".cshtml") || partialPath.EndsWith(".vbhtml"))
  33.             {
  34.                 return new RazorView(controllerContext, partialPath, null, false, null);
  35.             }
  36.             else
  37.             {
  38.                 return new WebFormView(controllerContext, partialPath);
  39.             }
  40.         }
  41.  
  42.         protected override IView CreateView(ControllerContext controllerContext, string viewPath, string masterPath)
  43.         {
  44.             if (viewPath.EndsWith(".cshtml") || viewPath.EndsWith(".vbhtml"))
  45.             {
  46.                 return new RazorView(controllerContext, viewPath, masterPath, false, null);
  47.             }
  48.             else
  49.             {
  50.                 return new WebFormView(controllerContext, viewPath, masterPath);
  51.             }
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement