MVC 自定义路由
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 自定义路由的更多相关文章
- ASP.NET MVC 自定义路由中几个需要注意的小细节
本文主要记录在ASP.NET MVC自定义路由时,一个需要注意的参数设置小细节. 举例来说,就是在访问 http://localhost/Home/About/arg1/arg2/arg3 这样的自定 ...
- MVC自定义路由02-实现IRouteConstraint限制控制器名
通过实现IRouteConstraint接口,实现对某个控制名进行限制.本篇把重点放在自定义约束,其余部分参考: MVC自定义路由01-为什么需要自定义路由 自定义约束前 using Syste ...
- MVC自定义路由01-为什么需要自定义路由
本篇体验自定义路由以及了解为什么需要自定义路由. 准备 □ View Models using System.Collections.Generic; namespace MvcApplicati ...
- MVC自定义路由实现URL重写,SEO优化
//App_Start-RouteConfig.cs public class RouteConfig { public static void RegisterRoutes(RouteCollect ...
- Mvc自定义路由让支持.html的格式
前言 在大多时候,我们都需要自定义路由,当我们设置为/list/1.html的时候,有的时候会出现以下异常. routes.MapRoute( "category", // 路由名 ...
- Asp.net MVC 自定义路由在IIS7以上,提示Page Not Found 解决方法
受限确保自定义路由在开发服务器上Ok! 然后在web.config的<webserver>节点下增加如下配置就好了. 1: <system.webServer> 2: &l ...
- ASP.NET MVC自定义路由 - 实现IRouteConstraint限制控制器名(转载)
自定义约束前 namespace MvcApplication2 { public class RouteConfig { public static void RegisterRoutes(Rout ...
- vs2017 mvc 自定义路由规则 出现 404.0 错误代码 0x80070002
自定义: WebApiConfig 里面最后增加 config.Services.Replace(typeof(IHttpControllerSelector), new NamespaceHttp ...
- Asp.net MVC 自定义路由
在做公司接口的时候 由于规范API 要用点分割. 如: HealthWay.controller.action 在MVC 4 下面做了个 路由配置如下: public override void R ...
随机推荐
- BZOJ 1912: [Apio2010]patrol 巡逻 (树的直径)(详解)
题目: https://www.lydsy.com/JudgeOnline/problem.php?id=1912 题解: 首先,显然当不加边的时候,遍历一棵树每条边都要经过两次.那么现在考虑k==1 ...
- gevent多协程运用
#导包 import gevent #猴子补丁 from gevent import monkey monkey.patch_all() from d8_db import ConnectMysql ...
- long long
1. ll a; scanf("%d",&a); 数据读入后,产生错误 2. const ll inf=1e18; 3. int * ll = ll ll * int = ...
- 函数:PHP将字符串从GBK转换为UTF8字符集iconv
1. iconv()介绍 iconv函数可以将一种已知的字符集文件转换成另一种已知的字符集文件.例如:从GB2312转换为UTF-8. iconv函数在php5中内置,GB字符集默认打开. 2. ic ...
- 计算机基础:计算机网络-chapter4 网络层
网络层的使用:如 ping,tracert,原理是ICMP 一.什么叫网络,网络层做什么,通过什么实现,这章的内容, 什么叫网络,实现这些需要做什么 将全世界范围内数以百万计的网络都互连起来,并且能够 ...
- c#中序列化和反序列化的理解
using System.IO;using System.Runtime.Serialization.Formatters.Binary; 序列化:对象转化为文件的过程(字节流) 反序列化:文件(字节 ...
- C++(3):./Encryptor: undefined symbol:Z11startserviceLAKJDFLJALDKJFLLLLL
在Linux下编译得Encryptor文件,但是执行./Encryptor时 报了如上错误:undefined symbol:Z11startserviceLAKJDFLJALDKJFLLLLL 原因 ...
- qml: C++调用qml函数
C++调用qml函数,是通过下面的函数实现的: bool QMetaObject::invokeMethod(QObject *obj, const char *member, Qt::Connect ...
- docker 基本功能
Docker开启Remote API docker默认是没有开启Remote API的,需要我们手动开启. 1.编辑/lib/systemd/system/docker.service文件: 注释掉图 ...
- eslint相关工具
eslint工具 1. vscode搜索eslint安装,就可以在写代码时报eslint的错误了 2.文件 --> 首选项 --> 设置 --> 选ESLint --> 勾选A ...