1.打开Global.asax文件
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
AuthConfig.RegisterAuth();
}
2.添加Application_Start方法
protected void Application_Start()
{
ViewEngines.Engines.Clear();//This clears all the Web form view engines.
}
3.修改Application_Start
protected void Application_Start()
{
ViewEngines.Engines.Clear(); //This clears all the view engines as mentioned earlier
ViewEngines.Engines.Add(new RazorViewEngine()); //This RazorViewEngine() is present in the System.Web.Mvc namespace
}
public class "your viewengine
name":RazorViewEngine //This RazorViewEngine in present in the System.Web.Mvc namespace
ViewLocationFormats = new[]
{
"~/Views/{1}/{0}.cshtml",
"~/Views/Shared/{0}.cshtml"
};
MasterLocationFormats = new[]
{
"~/Views/{1}/{0}.cshtml",
"~/Views/Shared/{0}.cshtml"
};
原文地址:http://www.codeproject.com/Tips/739847/Customizing-View-Engines