【发布时间】:2020-10-03 12:26:49
【问题描述】:
我想要一个如下所示的 URL:
如果 artCatId != null 并且 tagId == null:
/Article/artCatId/100/pageNumber/2
或
如果 artCatId == null 并且 tagId != null:
/Article/tagId/200/pageNumber/3
如果 artCatId != null 和 tagId != null:
/Article/artCatId/100/tagId/200/pageNumber/3
我怎样才能创建这个漂亮的 URL?
我在我的项目中使用了 ASP.NET Core 3.1。
在控制器中:
public async Task<IActionResult> Index(int? artCatId = null, int? tagId = null, int pageNumber = 1)
{
}
在 Startup.cs 中:
app.UseEndpoints(endpoints =>
{
// This doesn't work based on my expectation
endpoints.MapControllerRoute(name: "article cat or tag", pattern: "{controller=Article}/{action}/artCatId/{artCatId?}/tagId/{tagId?}/pageNumber/{pageNumber}");
}
【问题讨论】:
标签: c# asp.net-core url url-routing asp.net-core-3.0