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. centos7下利用httpd2.4配置svn并使用Ldap用户认证

    应用场景:Windows下有AD活动目录,类Unix系统下有Ldap,在运维开发工具平台逐步丰富的现在,统一用户管理大大便捷了管理人员. 其中不乏经典版本控制管理工具svn,与Ldap组合的用户认证方 ...

  2. jsp (1)

    一.jsp介绍: jsp是servlet的一种包装.是html+js+css+servlet. jsp文件无需配置,如果修改了jsp文件不需要reload应用. jsp访问方法:直接访问文件名.jsp ...

  3. OnCheckedChangeListener和setChecked之间冲突问题解决

    判断是否点击!buttonView.isPressed()来解决 CompoundButton.OnCheckedChangeListener checkedChangeListener = new ...

  4. 一个ArrayList在循环过程中删除,会不会出问题,为什么?

    ArrayList中的remove方法(注意ArrayList中的remove有两个同名方法,只是入参不同,这里看的是入参为Object的remove方法)是怎么实现的: public boolean ...

  5. [NOI2018]归程

    今年D1T1,平心而论,如果能想到kruskal重构树还是很简单的. ......苟屁啊!虽然跟其他的比是简单些,但是思维难度中上,代码难度中上,怎么看都很符合NOI T1啊. 本题还有可持久化并查集 ...

  6. axios 使用

    <!DOCTYPE html> <html lang="en"> <head> {#导入静态文件#} {% load static %} < ...

  7. ImageMagick 笔记: 索引颜色(index color)、锁定图层,透明 png 转 gif (保持清晰度)

    今天在处理一张 png 透明背景的图片,大小: 16KB, 尺寸: 400 x 300,用到一段代码,也许对以后有用. /** 带透明背景和阴影的png图片, 转换成 gif, [索引色] + [锁住 ...

  8. python基础之IO编程

    读文件 with open('/path/to/file', 'r') as f: print(f.read()) 调用read()会一次性读取文件的全部内容,read()函数里面可以传入每次最多读取 ...

  9. PHP ACCESS-CONTROL-ALLOW-ORIGIN ,设置跨域头

    php里允许别的域名跨域访问,先解释下跨域 跨域,指的是浏览器不能执行其他网站的脚本.它是由浏览器的同源策略造成的,是浏览器对javascript施加的安全限制. 所谓同源是指,域名,协议,端口均相同 ...

  10. jenkins发版svn

    1.在mac上直接安装Jenkins,下载地址 : 2.安装插件:系统管理-->插件管理 publish over ssh Exec command: cd /usr/local/apache- ...