在我的网站中,我通过使用 slug 使我的 url 通常更加友好。我也想通过更改
使与分页相关的 url 信息更加友好 www.example.com/controller/action/1 // 1 represents the page
到
www.example.com/controller/action/page-1
我不在乎这是否可能,但这是可取的。
我试着用
装饰我的 Action[Route("action/page-{pagina?}")]
public IActionResult Action(int page= 1)
导航时得到这个。
可选参数“page”前面有一个无效段“page-”
最佳答案
我已经在我的 Startup.cs
中的 Configure 方法中成功完成了此操作
app.UseMvc(routes => {
/* code removed for brevity */
routes.MapRoute(
name: "RouteName",
template: "action/page-{pageNumber}",
defaults: new { Controller = "YourController", Action = "Action" }
);
});
然后您的 Controller 将是...
public IActionResult Action(int page= 1)
这取决于你是否需要使用属性路由。
关于c# - 路由添加静态段让分页更友好asp.net core,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45556472/