在不同的视图ASP MVC 3使用不同的布局 [英] ASP MVC 3 use different Layouts in different views
问题描述
我有一个ASP MVC应用程序,需要多种不同的布局。在ASP.NET Web应用程序我刚才提出不同的母版页。如何在ASP MVC 3要这样做呢?
I have an ASP MVC application which needs multiple different layouts. In ASP.NET Web Apps I would have just made separate master pages. How do I do this in ASP MVC 3?
到目前为止,我已经做了一个单独的文件Layout.cshtml为每个布局我需要的。
So far I have made a separate Layout.cshtml file for each layout I need.
我试图在视图中设置布局,但它正从它设回默认布局站点的ViewStart.cshtml吹走。
I tried setting the layout in the view but it is getting blown away from the ViewStart.cshtml which is setting it back to the default layout for the site.
另外,我似乎无法得到智能感知与剃刀工作,所以我一直没能去探索很多东西,我可以在ViewStart做的,如果我可以有条件地设置布局,还是什么。
Also, I can't seem to get intellisense working with Razor so I haven't been able to explore much of what I can do in the ViewStart, if I can conditionally set the Layout, or what.
思考?
推荐答案
您可以在动态控制器操作设置的布局:
You could set the layout dynamically in your controller action:
public ActionResult Index()
{
var viewModel = ...
return View("Index", "_SomeSpecialLayout", viewModel);
}
这篇关于在不同的视图ASP MVC 3使用不同的布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!