【问题标题】:Visual Studio 2019 for Mac: "The name layout does not exist in the current context"Visual Studio 2019 for Mac:“当前上下文中不存在名称布局”
【发布时间】:2020-04-14 10:04:18
【问题描述】:

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

我已经查看了有关此主题的类似问题,但没有设法解决。我的 Views\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 does't exist in current context 它提供了一些代码以添加到 web.config 文件中,但它与我已经拥有的相同(除了我最近的一些版本那些)。

【问题讨论】:

    标签: asp.net-mvc visual-studio asp.net-mvc-4


    【解决方案1】:

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

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

    在 /Views/Shared 中确保你有这个文件 _Layout.cshtml

    在 References 下检查以确保您拥有 System.Web.WebPages。

    【讨论】:

    • 谢谢 - 我确定我已经配置了这三个东西,但仍然遇到同样的问题。
    猜你喜欢
    • 2012-08-17
    • 2015-06-01
    • 2016-05-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-14
    • 1970-01-01
    • 2012-12-05
    • 1970-01-01
    相关资源
    最近更新 更多