當(dāng)前位置:
首頁 >
MVC自定义视图规则
發(fā)布時(shí)間:2025/7/14
43
豆豆
生活随笔
收集整理的這篇文章主要介紹了
MVC自定义视图规则
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
自定義規(guī)則:
using System.Web.Mvc; using System.Configuration;namespace Research {public class ViewConfig{public static void RegisterView(){string temp = ConfigurationManager.AppSettings["ShopTemplate"];RazorViewEngine r = new RazorViewEngine();r.ViewLocationFormats = new[] { "~/Template/" + temp + "/{1}/{0}.cshtml", "~/Views/{1}/{0}.cshtml" };ViewEngines.Engines.Clear();ViewEngines.Engines.Add(r);}} }注冊自定義規(guī)則:在Global.asax.cs中加入注冊代碼
public class MvcApplication : System.Web.HttpApplication{protected void Application_Start(){AreaRegistration.RegisterAllAreas();FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);RouteConfig.RegisterRoutes(RouteTable.Routes);BundleConfig.RegisterBundles(BundleTable.Bundles);//注冊自定義視圖訪問規(guī)則 ViewConfig.RegisterView();}}?
總結(jié)
以上是生活随笔為你收集整理的MVC自定义视图规则的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 今年阿里双十一CDN要冲历史之最,峰值带
- 下一篇: 每天进步一点之C\C++