zoukankan      html  css  js  c++  java
  • 关于路由约束

      // home/print/1
            public ActionResult PRInt(int id)
            {
                return Content(" Id = "+id.ToString());
            }
    
            // home/prname/james
            public ActionResult PRName(string name)
            {
                return Content(" name = " + name);
            }
      routes.MapRoute(
                    name: "Default",
                    url: "{controller}/{action}/{id}",
                    defaults: new { controller = "Home", action = "Add", id = UrlParameter.Optional },
                    constraints: new {id = @"d*" }//为{id}占位符 设置约束,必须是 数值
                );
    
                routes.MapRoute(
                    name: "Default2",
                    url: "{controller}/{action}/{name}",
                    defaults: new { controller = "Home", action = "Add", name = UrlParameter.Optional },
                    constraints: new { name = "[a-z]+" }//为{name}占位符 设置约束,必须是 字母
                );
    
                routes.MapRoute(
                    name: "Default3",
                    url: "{action}/{controller}/{name}",
                    defaults: new { controller = "Home", action = "Add", name = UrlParameter.Optional },
                    constraints: new { name = "[a-z]+" }//为{name}占位符 设置约束,必须是 字母
                );
  • 相关阅读:
    [LuoGu] P1004 方格取数
    [LuoGu] P1018 乘积最大
    [LuoGu] P2758 编辑距离
    [JZOJ] 01知多少
    [LuoGu] P1731 生日蛋糕
    $mathcal{Const,Inline,Register}$用法总结
    T2027 蜈蚣
    T57274 黑暗城堡
    P2312 解方程
    AT2412 最大の和
  • 原文地址:https://www.cnblogs.com/xiaoyangshu/p/12297724.html
Copyright © 2011-2022 走看看