我有以下项目结构:
_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。我期待 _Layout.cshtml 按照约定使用 _viewstart 应用于 _Blue.cshtml。相反,我得到了仅应用了 _Blue.cshtml 模板的 Index.cshtml 页面。
我的假设错了吗?
提前致谢!
更新:
控制器方法:
public ActionResult Index()
{
ViewBag.Message = "Welcome to ASP.NET MVC!";
return View("Index");
}
所以,我返回的是 ViewResult,而不是 PartialViewResult ;)