我有以下项目结构:_ViewStart.cshtml与嵌套布局
_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->红 - >我们的页面
但是,如果我尝试使用_Blue.cshtml渲染Index.cshtml,_Layout.cshtml不适用。 我期待_Layout.cshtml将按照惯例使用_viewstart应用于_Blue.cshtml。相反,我只用_Blue.cshtml模板来获取Index.cshtml页面。
我错在我的假设?
在此先感谢!
UPDATE:
控制器的方法:
public ActionResult Index()
{
ViewBag.Message = "Welcome to ASP.NET MVC!";
return View("Index");
}
所以,我回来的ViewResult,不PartialViewResult;)
您是否从控制器返回View或PartialView? – 2012-04-26 08:51:02
@Chuck Norris:对不起,忘了提及它,我正在返回查看(“索引”) – Andrey 2012-04-26 08:53:02