.net core3.1路由配置伪链接该怎么配置

2020-09-23 17:33发布

问题:

endpoints.MapControllerRoute(
name: "blog-list",
pattern: "{controller}/{category?}",
defaults: new { Controller = "Blog", Action = "List" }
);
endpoints.MapControllerRoute(
name: "blog-info",
pattern: "{controller}/{action}/{id?}"
);

比如说我想配置 /blog/58.html

其中58是id

回答1:

假如 Action 名称是 Info ,可以使用下面的路由配置

endpoints.MapControllerRoute(
    name: "blog-info",
    pattern: "{controller}/{id}.html",
    defaults: new { Controller = "Blog", Action = "Info" }
);