MVC 自定义路由
2024-08-22 05:57:03
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();
}
}
最新文章
- CocoaPod 使用方法
- POJ1190生日蛋糕[DFS 剪枝]
- dd命令使用详解
- 车牌识别LPR(五)-- 一种车牌定位法
- sql批量删除wordpress所有日志修订revision
- C++遍历目录,并把目录里超过7天的文件删除(跨平台windows&;linux)
- Invalid segment BIN$xxx and dba_recyclebin was empty (回收站空,释放无效的BIN$xx空间)
- Eratosthenes筛选法计算质数
- C#多线程编程(2)-- async,await基本用法
- org.apache.poi.ss.usermodel 类操作excel数据遗漏
- mysql进阶(六)模糊查询的四种用法介绍
- 第十六节,OpenCV(学习五)边缘检测
- RocketMQ基本概念
- 【转帖】Linux的历史----Linux内核剖析(一)
- 洛谷 P1110 [ZJOI2007]报表统计 解题报告
- 阿里P6大牛给予Java初学者的学习路线建议
- 如何为linux系统设置全局的默认网络代理
- Spring Boot学习笔记:JavaMailSender发送邮件
- statefulSet + headless service 学习记录 service :selector -->; template :label
- IT软件外包行业深入分析:现状、前途、趋势、待遇 什么是软件外包 外包公司是怎么工作的 软件外包公司的面试 软件外包公司需要什么样的人