<a>
現在のアクション以外のタグでasp-controller と asp-action を使用すると、[Route]
属性を持つコントローラー メソッドによって呼び出されるビューで、生成されたリンクのhref
属性が空になります。
コントローラーで:
public class ForumController : Controller
{
[Route("[action]/{sectionId:int}")]
public async Task<IActionResult> ShowSection(int sectionId)
{
//some code
}
}
ビューで:
<a asp-controller="Forum" asp-action="Index">Index</a>
<a asp-controller="Forum" asp-action="ShowSection" asp-route-sectionId="@Model.ParentSection.Id">@Model.ParentSection.Name</a>
生成されたhtml:
<a href="">Index</a>
<a href="/ShowSection/1">Général</a>
ご覧のとおり、最初のリンクが正しく生成されていません。現在のアクション以外の別のアクションを対象とするすべてのリンクは、空のhref
タグで生成されます。
ShowSection アクションの [Route] 属性を削除すると、次のようになります。
<a href="/Forum">Index</a>
<a href="/Forum/ShowSection?sectionId=1">Général</a>
ご覧のとおり、リンクは正しく生成されています。
[Route]
属性を保持しながら (または別の方法で) これを修正するにはどうすればよいですか?