mvc5新特性RouteAttribute特征路由

mvc5新特性RouteAttribute特征路由,本文讲述如何开启mvc5的RouteAttribute路由功能并附上一个实例说明RouteAttribute是怎么工作的
1、mvc5的RouteAttribute概述
RouteAttribute的命名空间是System.Web.Mvc,区别与web api的RouteAttribute(它的命名空间是System.Web.Http)
默认情况下mvc的特征路由(RouteAttribute)功能是关闭的,需要手动启动,启动方式:
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.MapMvcAttributeRoutes();//启用Attribute路由
            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
        }    
2、RouteAttribute简单实例
        [Route("list.html")]
        [Route("list_{category}.html")]
        [Route("list_{category}_p{page:int}.html")]
        public void ArticleList(string category, int page = 1)
        {
            var title = string.IsNullOrEmpty(category) ? "所有资讯" : category + "资讯";
            Response.Write(string.Format("分类:{0},页码:{1}<br/>我们都是好孩子!!!", title, page));
        }
  Route("list.html")匹配地址:http://localhost:2000/list.html
  
  Route("list/{category}.html")  匹配地址:http://localhost:2000/list/news.html
  
  Route("list/{category}/{page:int}.html")  匹配地址:http://localhost:2000/list/bews/2.html
  
  
mvc5新特性RouteAttribute特征路由由懒人建站收集整理,您可以自由传播,请主动带上本文链接
懒人建站就是免费分享,觉得有用就多来支持一下,没有能帮到您,懒人也只能表示遗憾,希望有一天能帮到您。
mvc5新特性RouteAttribute特征路由的更多相关文章
- ASP.NET MVC5 新特性:Attribute路由使用详解 (转载)
		
1.什么是Attribute路由?怎么样启用Attribute路由? 微软在 ASP.NET MVC5 中引入了一种新型路由:Attribute路由,顾名思义,Attribute路由是通过Attrib ...
 - ASP.NET MVC5 新特性:Attribute路由使用详解
		
1.什么是Attribute路由?怎么样启用Attribute路由? 微软在 ASP.NET MVC5 中引入了一种新型路由:Attribute路由,顾名思义,Attribute路由是通过Attrib ...
 - MVC5新特性(一)之RouteAttribute打造自己的URL规则
		
1.RouteAttribute概述 RouteAttribute的命名空间是System.Web.Mvc,区别与web api的RouteAttribute(它的命名空间是System.Web.Ht ...
 - Asp.Net Mvc5新特性
		
One ASP.NET:统一平台 BootStrap:免费Css响应式页面 路由标记属性:简单,控制器,操作,前缀,参数,URL ASP.NET WEB API 2:路由标记属性,Oauth2.0,O ...
 - 一、数据库表中字段的增删改查,二、路由基础.三、有名无名分组.四、多app共存的路由分配.五、多app共存时模板冲突问题.六、创建app流程.七、路由分发.八、路由别名,九、名称空间.十、反向解析.十一、2.x新特性.十二、自定义转换器
		
一.数据库表中字段的增删改查 ''' 直接在modules中对字段进行增删改查 然后在tools下点击Run manage.py Task执行makemigrations和migrate 注意在执行字 ...
 - django第四天(路由别名,django2.x新特性和自定义转换器)
		
django第四天 路由别名 1.路由别名: 给路由路径命名一个名字 url(r'^login/$',views.login,name = 'login') 2.为什么要用路由别名 ①当路由路径过长时 ...
 - 返璞归真 asp.net mvc (13) - asp.net mvc 5.0 新特性
		
[索引页][源码下载] 返璞归真 asp.net mvc (13) - asp.net mvc 5.0 新特性 作者:webabcd 介绍asp.net mvc 之 asp.net mvc 5.0 新 ...
 - php 新特性
		
PHP 5.6 1.可以使用表达式定义常量 https://php.net/manual/zh/migration56.new-features.php 在之前的 PHP 版本中,必须使用静态值来定义 ...
 - Spring Framework 5 中的新特性
		
https://www.ibm.com/developerworks/cn/java/j-whats-new-in-spring-framework-5-theedom/index.html Spri ...
 
随机推荐
- ajax dataType
			
dataType 类型:String 预期服务器返回的数据类型.如果不指定,jQuery 将自动根据 HTTP 包 MIME 信息来智能判断,比如 XML MIME 类型就被识别为 XML.在 1.4 ...
 - joyoi1864 守卫者的挑战
			
#include <algorithm> #include <iostream> #include <cstdio> using namespace std; in ...
 - 大数据学习——sqoop导出数据
			
把数据从hadoop导出到关系型数据库 将数据从HDFS导出到RDBMS数据库 导出前,目标表必须存在于目标数据库中. u 默认操作是从将文件中的数据使用INSERT语句插入到表中 u 更新模式下 ...
 - Leetcode 336.回文对
			
回文对 给定一组唯一的单词, 找出所有不同 的索引对(i, j),使得列表中的两个单词, words[i] + words[j] ,可拼接成回文串. 示例 1: 输入: ["abcd&quo ...
 - Laya Timer原理 & 源码解析
			
Laya Timer原理 & 源码解析 @author ixenos 2019-03-18 16:26:38 一.原理 1.将所有Handler注册到池中 1.普通Handler在handle ...
 - nginx的正则
			
~ 为区分大小写的匹配. ~* 不区分大小写的匹配(匹配firefox的正则同时匹配FireFox). !~ 不匹配的 !~* 不匹配的 . 匹配除换行符以外的 ...
 - android悬浮窗口的一些说明
			
1.xml文件里的权限申请 <uses-permission android:name="android.permission.SYSTEM_OVERLAY_WINDOW" ...
 - Spring Task Schedule 及多线程
			
http://spring.io/blog/2010/01/05/task-scheduling-simplifications-in-spring-3-0/‘ http://ekramalikazi ...
 - govalidator----结构体tag验证
			
github地址:https://github.com/asaskevich/govalidator govalidator支持内置支持的验证tag和自定义验证tag: package main im ...
 - 树莓派用gobot测试舵机的使用
			
package main import ( "gobot.io/x/gobot" "gobot.io/x/gobot/drivers/gpio" "g ...