Created
May 28, 2013 01:53
-
-
Save andyyou/5660067 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Globalization; | |
using System.Linq; | |
using System.Web; | |
using System.Web.Mvc; | |
namespace CoolProject | |
{ | |
public class NewViewEngine : RazorViewEngine | |
{ | |
public NewViewEngine() | |
{ | |
//var viewLocations = new[] { | |
// "~/Views/Administrator/{1}/{0}.cshtml" | |
//}; | |
//this.PartialViewLocationFormats = viewLocations; | |
//this.ViewLocationFormats = viewLocations; | |
} | |
public override ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache) | |
{ | |
string ns = controllerContext.Controller.GetType().Namespace; | |
string[] nss = ns.Split('.'); | |
if (nss.Length > 2) | |
{ | |
string controller = controllerContext.Controller.GetType().Name.Replace("Controller", ""); | |
string viewPath = string.Format("~/Views/{2}/{1}/{0}.cshtml", viewName, controller, nss[nss.Length - 1]); | |
// string masterPath = string.Format("~/Views/Shared/{0}/_Layout.cshtml", nss[nss.Length - 1]); | |
return new ViewEngineResult( | |
(this.CreateView(controllerContext, viewPath, null)), this); | |
} | |
return base.FindView(controllerContext, viewName, masterName, useCache); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment