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 ...
随机推荐
- Git同步远程fork的项目
通过fork创建的项目,如果远程仓库代码进行了更新,本地需要同步的话,可以在git上创建一个上游仓库 步骤 运行git remote add upstream https://github.com/O ...
- 【CSS 技能提升】 :before和:after的使用
前几天的晚上较全面的去看了下css的一些文档和资料,大部分的样式运用都没什么大问题了,只是有些许较陌生,但是也知道他们的存在和实现的是什么样式.今天主要想在这篇学习笔记中写的也不多,主要是针对:bef ...
- django 通过ajax完成登录
一. 在users/views.py中加代码: from django.http import HttpResponse class LoginView(View): ""&quo ...
- 认识Jmeter工具
1.Apache jmeter 是一个100%的纯java桌面应用,是Apache组织开发的基于java的压力测试工具.它最初被设计用于Web应用测试但后来扩展到其他测试领域,可以用于对静态的和动态的 ...
- TensorFlow升级1.4:Cannot remove entries from nonexistent file \lib\site-pack
https://blog.csdn.net/wishchin/article/details/78559313 https://blog.csdn.net/fool_frog/article/deta ...
- 第六节,Neural Networks and Deep Learning 一书小节(下)
4.神经网络可以计算任何函数的可视化证明 神经网络拥有一定的普遍性,即包含一个隐藏层的神经网络可以被用来按照任意给定的精度来近似任何连续函数. 这一章使用一个实例来阐述神经网络是如何来近似一个一元函数 ...
- Jquery Mobile事件
Jquery Mobile事件参考手册 on()方法用于添加事件处理程序 1.Touch类事件 在用户触摸屏幕时触发 1.1 tap事件 用户敲击某个元素时发生 $("p").on ...
- POJ 3268 Silver Cow Party (Dijkstra)
Silver Cow Party Time Limit: 2000MS Memory Limit: 65536K Total Submissions:28457 Accepted: 12928 ...
- (DFS)P1605 迷宫 洛谷
题目背景 迷宫 [问题描述] 给定一个N*M方格的迷宫,迷宫里有T处障碍,障碍处不可通过.给定起点坐标和 终点坐标,问: 每个方格最多经过1次,有多少种从起点坐标到终点坐标的方案.在迷宫 中移动有上下 ...
- win10 同步批处理禁用和启用网卡
@ echo off echo 正在启用超级管理员权限... %1 %2 ver|find "5.">nul&&goto :st mshta vbscript ...