shuhelohelo’s blog

Xamarin.Forms多めです.

ASP.NETでpartialタグで部分ビューが検索されるフォルダー一覧

環境は以下のとおり。

Razorビューで以下のように部分ビューを参照するとき、

<partial name="{部分ビュー名}" />

デフォルトでは以下のフォルダ内が検索される。

  • /Areas/Identity/Pages/Account/_FrontPartial.cshtml
  • /Areas/Identity/Pages/_FrontPartial.cshtml
  • /Areas/Identity/Pages/Shared/_FrontPartial.cshtml
  • /Areas/Identity/Views/Shared/_FrontPartial.cshtml
  • /Pages/Shared/_FrontPartial.cshtml
  • /Views/Shared/_FrontPartial.cshtml

これは部分ビューが見つからないときに表示される以下のエラーメッセージからわかる。

InvalidOperationException: The partial view '_FrontPartial' was not found. The following locations were searched:
/Areas/Identity/Pages/Account/_FrontPartial.cshtml
/Areas/Identity/Pages/_FrontPartial.cshtml
/Areas/Identity/Pages/Shared/_FrontPartial.cshtml
/Areas/Identity/Views/Shared/_FrontPartial.cshtml
/Pages/Shared/_FrontPartial.cshtml
/Views/Shared/_FrontPartial.cshtml
Microsoft.AspNetCore.Mvc.TagHelpers.PartialTagHelper.RenderPartialViewAsync(TextWriter writer, object model)

これらのフォルダ内にある.cshtmlファイルであれば、タグで名前だけで指定できる。

<partial name="_FrontPartial" />