Visual Studio 2019 for Mac:"名称布局在当前上下文中不存在"



我在 VS19 for Mac 中创建了一个 ASP.NET MVC 应用程序。但是,在我自己向框架添加任何内容之前,我在 _ViewStart.cshtml 文件中收到错误"当前上下文中不存在名称'布局'"。

我已经看过关于这个主题的类似问题,但还没有设法解决它。我的视图\Web.config文件在这里:

<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>
</configSections>
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="Vidly" />
</namespaces>
</pages>
</system.web.webPages.razor>
<appSettings>
<add key="webpages:Enabled" value="false" />
</appSettings>
<system.webServer>
<handlers>
<remove name="BlockViewHandler" />
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>
</system.webServer>
</configuration>

我看了这个类似的问题:VS2019 - ViewBag 在当前上下文中不存在,它提供了一些代码以添加到 web.config 文件中,但它与我已经拥有的代码相同(除了一些版本我有更新的版本(。

在 _ViewStart.cshtml 中确保你有这个,

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

并在/Views/Shared 中确保将此文件_Layout.cshtml

在"引用"下检查以确保您具有 System.Web.WebPages。

最新更新