ビュー、コントローラー、モデルをグループ化しています。構造は
~/Controllers
-- /_Shared
-- -- /Views
-- -- /Content
-- -- /Scripts
-- /Home
-- -- /Models
-- -- /Content
-- -- /Scripts
-- -- /Views
-- -- HomeController.cs
-- /Account
-- -- /Models
-- -- /Views
...
ビューと部分ビューは機能しますが、レイアウト(マスター ビュー)は機能しません。次のような .cshtml ファイルでレイアウトを指定すると:
@{ Layout = "SimpleSharedLayout"; }
次のエラーが表示されます: レイアウト ページ "SimpleLayout" が次のパスに見つかりませんでした:
"~/Controllers/Account/Views/SimpleSharedLayout".
Asp.NET は、現在のコントローラーのディレクトリ内のレイアウトのみを検索し、Shared フォルダーを調べません*(~/Controllers/_Shared/Views にあります)*
これはうまくいきますが。
@Html.Partial("SharedPartialView")
次のようなフルパスでレイアウトを指定する必要があります
@{ Layout = "~/Controllers/_Shared/Views/SimpleSharedLayout.cshtml"; }
これは難しいことではありませんが、うまくいかないことに夢中です。
IIS Express、VS 2012、.NET 4.5 の使用
私が欠けているものについてのアイデアはありますか?
私のビューエンジン:
public class AreaViewEngine : RazorViewEngine
{
public AreaViewEngine()
{
AreaViewLocationFormats = new[] {
"~/Controllers/{1}/Views/{0}.cshtml",
"~/Controllers/_Shared/Views/{0}.cshtml"};
ViewLocationFormats = AreaViewLocationFormats;
AreaMasterLocationFormats = new[] { "~/Controllers/_Shared/Views/{0}.cshtml" };
MasterLocationFormats = AreaMasterLocationFormats;
AreaPartialViewLocationFormats = new[] { "~/Controllers/_Shared/Views/{0}.cshtml",
"~/Controllers/{1}/Views/{0}.cshtml"};
PartialViewLocationFormats = AreaPartialViewLocationFormats;
}
}