C# 省略URL的中间部分

C# 省略URL的中间部分,c#,asp.net-core-mvc,asp.net-routing,asp.net-core-routing,C#,Asp.net Core Mvc,Asp.net Routing,Asp.net Core Routing,我正在开发一个博客web应用程序,我希望个人博客帖子链接如下:http://example.com/Post/2017/1/22/post-title,但同时,如果一天中有两篇以上的文章,那么第二篇文章的链接应该是http://example.com/Post/2017/1/22/2/another-post-title。目前,我已通过以下方式实施: [AllowAnonymous] [Route("Post/{year:int}/{month:int}/{day:int}/{*title}")

我正在开发一个博客web应用程序,我希望个人博客帖子链接如下:
http://example.com/Post/2017/1/22/post-title
,但同时,如果一天中有两篇以上的文章,那么第二篇文章的链接应该是
http://example.com/Post/2017/1/22/2/another-post-title
。目前,我已通过以下方式实施:

[AllowAnonymous]
[Route("Post/{year:int}/{month:int}/{day:int}/{*title}")]
[HttpGet]
public Task<IActionResult> GetPostByDateTitle(int year, int month, int day, string title)
{
    return this.GetPostByDate(year, month, day, 1);
}

[AllowAnonymous]
[Route("Post/{year:int}/{month:int}/{day:int}/{dayId:int}/{*title}")]
[HttpGet]
public Task<IActionResult> GetPostByDateTitle(int year, int month, int day, int dayId, string title)
{
    return this.GetPostByDate(year, month, day, dayId);
}
[AllowAnonymous]
[路线(“Post/{year:int}/{month:int}/{day:int}/{*title}”)]
[HttpGet]
公共任务GetPostByDateTitle(整数年、整数月、整数日、字符串标题)
{
返回此.GetPostByDate(年、月、日、1);
}
[异名]
[路线(“Post/{year:int}/{month:int}/{day:int}/{dayId:int}/{*title}”)]
[HttpGet]
公共任务GetPostByDateTitle(整数年、整数月、整数天、整数天ID、字符串标题)
{
返回此.GetPostByDate(年、月、日、日ID);
}
还有剃刀代码:

@if (Model.DayId == 1)
{
    <a asp-controller="Post" asp-action="GetPostByDateTitle" asp-route-year="@Model.Year" asp-route-month="@Model.Month" asp-route-day="@Model.Day" asp-route-title="@LinkTitle(Model.Title)">link</a>
}
else
{
    <a asp-controller="Post" asp-action="GetPostByDateTitle" asp-route-year="@Model.Year" asp-route-month="@Model.Month" asp-route-day="@Model.Day" asp-route-dayid="@Model.DayId" asp-route-title="@LinkTitle(Model.Title)">link</a>
}
@if(Model.DayId==1)
{
链接
}
其他的
{
链接
}
title
总是被忽略,它的存在只是为了让URL更具可读性,所以它会被解析,但会被忽略。我真正想要的是使
dayId
part成为可选的,而不必求助于两种方法,并检查Razor代码以确定调用哪一种方法。我该怎么做