asp.net - 当前上下文中不存在布局
问题描述
我试图将布局包含在我的一个视图中,它说它在当前上下文中不存在于 viewbag 中。
@{
ViewBag.Title = "About Me";
Layout = "~/Views/Shared/_Layout.cshtml";}
我查看了其他解决方案,说我在 web.config 中需要这个或那个,但没有任何效果。
我在 Mac OS 上并使用 Visual Studio for Mac 社区
意见/web.config:
<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.7.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="GroundRoots" />
</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>
根 web.config:
<!--
Web.config file for GroundRoots.
The settings that can be used in this file are documented at
http://www.mono-project.com/Config_system.web and
http://msdn2.microsoft.com/en-us/library/b5ysx397.aspx
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5">
<assemblies />
</compilation>
<httpRuntime targetFramework="4.5" />
</system.web>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-5.2.7.0" newVersion="5.2.7.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.webServer>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer></configuration>
真的不知道从这里去哪里......
解决方案
布局是否适用于其他视图?尝试创建一个新视图并选中“使用布局页面”,然后选择您的布局视图文件。希望这有效,它一直对我有用
推荐阅读
- php - 如何仅为访问者创建重定向(不适用于搜索机器人)
- docker - Docker compose 使用 up 命令无意中重新创建图像
- string - python列表中的唯一元素
- javascript - 将 Shopify 访问令牌发送给客户端会是一个坏主意吗?
- javascript - 标记一个元素时验证所需的复选框
- regex - 正则表达式在bash中的值和键周围添加双引号
- azure - Dynamics CRM 365 - 使用虚拟实体
- java - 我有一个由多个 json 元素组成的字符串,而这些元素又由多个元素组成,如何将其转换为 json 对象
- swift - 要求协议实现者用@objc 标记函数
- python - jupyter notebook 找不到肯定安装的 python 模块