Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.Net Core View: the name "Layout" does not exist in the current context

I'm using Visual Studio 2017 to build a .net core mvc project.

When I add a view in this way: Right click folder -> Add View -> Add enter image description here

enter image description here

Then the name "Layout" does not exist in the current context enter image description here

Restart vs or build the project this error still exist.

However, If I add view in this way:

Right click folder -> Add New Items -> MVC View Page enter image description here

the Layout can be recognized.

Is there any difference?

like image 969
wtf512 Avatar asked Mar 10 '17 04:03

wtf512


1 Answers

If you are using vs 2017 you have to add this code in new csproj which you created.

<PropertyGroup>
    <OutputType>Library</OutputType>
</PropertyGroup>

Because When you create a new Web application, this gets set to the "Web" SDK:

<Project Sdk="Microsoft.NET.Sdk.Web">...</Project>

so the Web SDK imports additional tasks to allow design-time processing of Web resources, such as Razor views. Change the SDK in your plugin library to Web. after you build error should be vanished.

like image 183
Ali Eshghi Avatar answered Oct 27 '22 08:10

Ali Eshghi