RouteConfig.cs 代码如下:

 public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); //自定义路由标签
routes.MapMvcAttributeRoutes(); //默认路由
//routes.MapRoute(
// name: "Default",
// url: "{controller}/{action}/{id}",
// defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
// namespaces: new string[] { "WebTest.Controllers" }
//);
}
}

Controller自定义路由标签:

 [RoutePrefix("Test")]
public class ProductController : Controller
{ [HttpGet,Route("Index")]
public ActionResult Index(int? pageIndex=,int? pageSize=)
{
ProductService service = new ProductService();
int index = Convert.ToInt32(pageIndex);
int size = Convert.ToInt32(pageSize);
var list = service.GetList(index, size);
ViewBag.products = list;
return View();
} [HttpGet,Route("Demo")]
public ActionResult One()
{
List<UserModel> list = new List<UserModel>();
for (int i = ; i < ; i++)
{
list.Add(new UserModel()
{
Id = i,
Name = "test"+i,
Password = ""
});
}
ViewBag.Users = list;
return View();
}
}

MVC 自定义路由的更多相关文章

  1. ASP.NET MVC 自定义路由中几个需要注意的小细节

    本文主要记录在ASP.NET MVC自定义路由时,一个需要注意的参数设置小细节. 举例来说,就是在访问 http://localhost/Home/About/arg1/arg2/arg3 这样的自定 ...

  2. MVC自定义路由02-实现IRouteConstraint限制控制器名

    通过实现IRouteConstraint接口,实现对某个控制名进行限制.本篇把重点放在自定义约束,其余部分参考: MVC自定义路由01-为什么需要自定义路由    自定义约束前 using Syste ...

  3. MVC自定义路由01-为什么需要自定义路由

    本篇体验自定义路由以及了解为什么需要自定义路由. 准备 □ View Models using System.Collections.Generic;   namespace MvcApplicati ...

  4. MVC自定义路由实现URL重写,SEO优化

    //App_Start-RouteConfig.cs public class RouteConfig { public static void RegisterRoutes(RouteCollect ...

  5. Mvc自定义路由让支持.html的格式

    前言 在大多时候,我们都需要自定义路由,当我们设置为/list/1.html的时候,有的时候会出现以下异常. routes.MapRoute( "category", // 路由名 ...

  6. Asp.net MVC 自定义路由在IIS7以上,提示Page Not Found 解决方法

    受限确保自定义路由在开发服务器上Ok! 然后在web.config的<webserver>节点下增加如下配置就好了.   1: <system.webServer> 2: &l ...

  7. ASP.NET MVC自定义路由 - 实现IRouteConstraint限制控制器名(转载)

    自定义约束前 namespace MvcApplication2 { public class RouteConfig { public static void RegisterRoutes(Rout ...

  8. vs2017 mvc 自定义路由规则 出现 404.0 错误代码 0x80070002

    自定义: WebApiConfig  里面最后增加 config.Services.Replace(typeof(IHttpControllerSelector), new NamespaceHttp ...

  9. Asp.net MVC 自定义路由

    在做公司接口的时候  由于规范API 要用点分割. 如: HealthWay.controller.action 在MVC 4 下面做了个 路由配置如下: public override void R ...

随机推荐

  1. webpack入门(三)webpack的api

    终于到了webpack api这一篇,我都等不及了0.0; webpack is fed a configuration object. Depending on your usage of webp ...

  2. vue.js自定义组件directives

    自定义指令:以v开头,如:v-mybind. <input v-mybind /> directives:{ mybind:{ bind:function (el) { el.value ...

  3. 在html页面通过js实现复制粘贴功能

    前言:要实现这个功能,常用的方式大概分为两类,第一种就是上插件,这个网上有大把,第二种就是直接用几行JS来实现. 这次说第二种实现方式,这方式有很大的局限性,只能用表单元素,并且不能设置disable ...

  4. 第一篇-Git基础学习

    学习网址: https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/0013758410 ...

  5. 第十三节、SURF特征提取算法

    上一节我们已经介绍了SIFT算法,SIFT算法对旋转.尺度缩放.亮度变化等保持不变性,对视角变换.仿射变化.噪声也保持一定程度的稳定性,是一种非常优秀的局部特征描述算法.但是其实时性相对不高. SUR ...

  6. maven+testng+eclipse

    1.安装maven 2.安装testng 3.配置maven的dependency,和build <project xmlns="http://maven.apache.org/POM ...

  7. JavaBean+Servlet 开发时,JavaBean 编写问题

    在开发 JavaBean 时,遇见一个问题: *****  表单字段为空,提交时出现 nullPointerException 异常:  表单字段不为空,提交正常. 使用 JavaBean ,JSP页 ...

  8. 1、CC2530单片机介绍

    单片机是一种集成电路芯片,包含中央处理器CPU.随机存储器RAM.只读存储器ROM.输入输出I/O接口.中断控制系统.定时/计数器和通信等多种功能部件. 本教程使用的单片机德州仪器生产的CC2530, ...

  9. 使用 windows 下的 secureCRT 软件的 通过 sftp 上传和下载文件到远端 linux 设备

    secureCRT 按下ALT+P就开启新的会话进行ftp操作. 输入:help命令,显示该FTP提供所有的命令 pwd:  查询linux主机所在目录(也就是远程主机目录) lpwd: 查询本地目录 ...

  10. aggregate聚合

    最近使用mongodb需要查询数据,用到了aggregate,学习下,上代码 db.表名.aggregate([ {$match:{'created_time':{$gte:'2016-01-15', ...