剃刀布局不工作,如果文件名为_ViewStart.cshtml [英] Razor Layout doesn't work if file is called _ViewStart.cshtml
问题描述
我有一个MVC3 Web应用程序,而我想开始使用全剃刀意见。
I have an MVC3 web app to which I want to start using whole Razor views.
大多数网站的工作正常使用的Site.Master所以我打包大部分为部分意见,我试图用相同的内容添加布局。
Most of the site is working fine with a Site.Master so I've packaged up most of it into partial views and am trying to add a layout with the same content.
阅读斯科特谷的博客后,我添加了一个名为_ViewStart.cshtml文件在我的〜/浏览目录,以便它会被默认使用。
After reading Scott Gu's blog I've added a file called _ViewStart.cshtml in my ~/Views directory so that it'll be applied by default.
可惜,这给我的错误:
The name 'RenderBody' does not exist in the current context
如果文件名为 _viewstart.cshtml
。
如果它被称为 _layoutviewstart.cshtml
将工作,但我必须直接在视图中引用它。
If it is called _layoutviewstart.cshtml
it will work but I have to reference it directly in the view.
如果这就是所谓的 _billyviewstart.cshtml
是工作,但我又不得不引用它直接在视图中。
If it's called _billyviewstart.cshtml
is works but again I have to reference it directly in the view.
推荐答案
查看启动
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
Layout.cshtml
Layout.cshtml
<!DOCTYPE html>
<html>
<body>
@RenderBody()
</body>
</html>
这篇关于剃刀布局不工作,如果文件名为_ViewStart.cshtml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!