次のプロジェクト構造があります。
_ViewStart.cshtml:
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
_Red.cshtml:
@{
ViewBag.Title = "Red";
Layout = "~/Views/Shared/_Layout.cshtml";
}
_Blue.cshtml には、明示的に指定されたレイアウトがありません。
_Red.cshtml レイアウトを使用して Index.cshtml をレンダリングしようとすると、_Layout.cshtml も階層的に適用されます。基本的に、ネストされたテンプレート チェーン _Layout->Red->Our page があります。
しかし、_Blue.cshtml を使用して Index.cshtml をレンダリングしようとすると、_Layout.cshtml が適用されません。_viewstart を使用する規則により、_Layout.cshtml が _Blue.cshtml に適用されることを期待していました。代わりに、_Blue.cshtml テンプレートのみが適用された Index.cshtml ページを取得します。
私の仮定は間違っていますか?
前もって感謝します!
アップデート:
コントローラーの方法:
public ActionResult Index()
{
ViewBag.Message = "Welcome to ASP.NET MVC!";
return View("Index");
}
したがって、PartialViewResult ではなく、ViewResult を返しています ;)