Suddenly getting “…'Layout' does not exist

2019-07-05 02:37发布

问题:

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