Razor Layout doesn't work if file is called _ViewStart.cshtml

旧街凉风 提交于 2020-01-10 19:09:08

问题


I have an MVC3 web app to which I want to start using whole Razor views.

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.

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.

Unfortunately this gives me the error:

The name 'RenderBody' does not exist in the current context

If the file is called _viewstart.cshtml.

If it is called _layoutviewstart.cshtml it will work but I have to reference it directly in the view.

If it's called _billyviewstart.cshtml is works but again I have to reference it directly in the view.


回答1:


View start

@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}

Layout.cshtml

<!DOCTYPE html>
<html>
<body>
     @RenderBody()
</body>
</html>


来源:https://stackoverflow.com/questions/7025057/razor-layout-doesnt-work-if-file-is-called-viewstart-cshtml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!