zoukankan      html  css  js  c++  java
  • MVC 路由配置

     1 RouteConfig
     2 public class RouteConfig
     3     {
     4         public static void RegisterRoutes(RouteCollection routes)
     5         {
     6             routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
     7 
     8             routes.MapRoute(
     9           name: "JianJie",
    10           url: "JianJie/{controller}/{action}/{id}",
    11           defaults: new { controller = "Index", action = "Index", id = UrlParameter.Optional }
    12       );
    13 
    14             routes.MapRoute(
    15              name: "bupin",
    16              url: "BuPin/{controller}/{action}/{id}",
    17              defaults: new { controller = "Index", action = "Index", id = UrlParameter.Optional }
    18          );
    19 
    20             routes.MapRoute(
    21                name: "Zhipin",
    22                url: "ZhiPin/{controller}/{action}/{id}",
    23                defaults: new { controller = "Index", action = "Index", id = UrlParameter.Optional }
    24            );
    25             routes.MapRoute(
    26                name: "Test",
    27                url: "Test/{controller}/{action}/{id}",
    28                defaults: new { controller = "Index", action = "Index", id = UrlParameter.Optional }
    29            );
    30 
    31             routes.MapRoute(
    32                 name: "Default",
    33                 url: "{controller}/{action}/{id}",
    34                 defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
    35             );
    36 
    37 
    38         }
    39     }
    40 
    41 
    42 MyViewEngine
    43   public class MyViewEngine:RazorViewEngine
    44     {
    45         public MyViewEngine()
    46         {
    47             ViewLocationFormats = new[]
    48             {
    49                 "~/Views/{1}/{0}.cshtml",
    50                 "~/Views/Shared/{0}.cshtml",
    51                 "~/Views/BuPin/{1}/{0}.cshtml",//我们的规则
    52                 "~/Views/ZhiPin/{1}/{0}.cshtml",//我们的规则
    53                 "~/Views/JianJie/{1}/{0}.cshtml",//我们的规则
    54                 "~/Views/Test/{1}/{0}.cshtml"//我们的规则
    55             };
    56         }
    57         public override ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache)
    58         {
    59             return base.FindView(controllerContext, viewName, masterName, useCache);
    60         }
    61     }
    62 
    63 Global
    64   public class MvcApplication : System.Web.HttpApplication
    65     {
    66         protected void Application_Start()
    67         {
    68             AreaRegistration.RegisterAllAreas();
    69             FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
    70             RouteConfig.RegisterRoutes(RouteTable.Routes);
    71             BundleConfig.RegisterBundles(BundleTable.Bundles);
    72             RegisterView();
    73         }
    74 
    75         protected void RegisterView()
    76         {
    77             ViewEngines.Engines.Clear();
    78             ViewEngines.Engines.Add(new MyViewEngine());
    79         }
    80     }
  • 相关阅读:
    学习笔记
    js闭包
    一个非必现问题的定位和反思
    C语言的设计模式面向对象机制的实现(一)
    多线程和单线程的执行效率问题
    python 多态
    C语言的设计模式接口隔离
    构建表达式二叉树
    C语言的设计模式依赖倒置
    C语言的设计模式单一职责
  • 原文地址:https://www.cnblogs.com/haigui-zx/p/14843923.html
Copyright © 2011-2022 走看看