Suddenly getting “…'Layout' does not exist in current context” in _ViewStart.cshtml

微笑、不失礼 提交于 2020-01-04 04:08:12

问题


I have a MVC 3 project that I deployed about a year ago then moved on.

The client asked for some mods and I re-opened the solution to find the red squiggly line error in the _ViewStart.cshtml file.

I fixed the assembly System.Web.MVC version issue (3.0.0.0->3.0.0.1), but I have no idea why this is happening. I'm also getting the same red squiggly with @RenderBody() in the _Layout_.cshtml file.

Nothing has been changed and it compiled and ran fine last I looked. I suspect Windows update may be involved given the MVC assembly issue.

Oddly enough, when I create a brand new MVC 3 project, that project builds and deploys perfectly.

I'm using VS2010 with .NET 4.0.

This is the only code in _ViewStart.cshtml:

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

回答1:


I had the same error and the error went away when I added the nuget package for Microsoft.AspNet.Mvc




回答2:


In my case I set "Copy local" to false for references in the project (I was trying something) to have only my DLLs in "bin" directory. So all "System.Web.*" binaries were missing (after cleanup). So as I understand, you have to have MVC related binaries in your bin folder otherwise intellisense will not work properly..

VS 2019 Preview



来源:https://stackoverflow.com/questions/28060976/suddenly-getting-layout-does-not-exist-in-current-context-in-viewstart-c

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