asp.net-mvc – Visual Studio无法解析模型,但加载了Razor页面
发布时间:2020-05-24 12:32:07 所属栏目:asp.Net 来源:互联网
导读:我有一个MVC 5应用程序,由空模板制作.我通过Nuget添加了Microsoft.AspNet.Mvc,我的包文件如下所示: packages package id=Microsoft.AspNet.Mvc version=5.2.3 targetFramework=net46 / package id=Microsoft.AspNet.Razor versio
|
我有一个MVC 5应用程序,由空模板制作.我通过Nuget添加了Microsoft.AspNet.Mvc,我的包文件如下所示: <packages> <package id="Microsoft.AspNet.Mvc" version="5.2.3" targetFramework="net46" /> <package id="Microsoft.AspNet.Razor" version="3.2.3" targetFramework="net46" /> <package id="Microsoft.AspNet.WebPages" version="3.2.3" targetFramework="net46" /> <package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="1.0.0" targetFramework="net46" /> <package id="Microsoft.Net.Compilers" version="1.0.0" targetFramework="net46" developmentDependency="true" /> <package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net46" /> </packages> 我有一个Razor页面,用@model IEnumerable< Models.ToDoModel>声明了一个模型.并在foreach循环中使用它. @model IEnumerable<Models.ToDoModel>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Home</title>
</head>
<body>
<h1>Hello World!</h1>
<ul>
@foreach (var item in Model)
{
<li>ID: @item.Id</li>
}
</ul>
</body>
</html>
当我运行页面时,它呈现正常,但Visual Studio坚持说有一个错误: 它不会识别模型关键字或给我任何智能感知. 我的Web.Config看起来像这样: <?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application,please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.6"/>
<httpRuntime targetFramework="4.6"/>
</system.web>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider,Microsoft.CodeDom.Providers.DotNetCompilerPlatform,Version=1.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701"/>
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider,PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE="Web" /optionInfer+"/>
</compilers>
</system.codedom>
<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.3.0" newVersion="5.2.3.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
和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,PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection,PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection,PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>
</configSections>
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory,System.Web.Mvc,Version=5.2.3.0,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" />
</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.configs看起来都很好. Visual Studio经常会对此类事情感到困惑.我的建议是关闭Visual Studio并重新打开它.此外,正如您所发现的,可能需要关闭VS的所有打开实例.(编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc-4 – 如何解决Antlr3依赖地狱
- asp.net-mvc – ASP.Net MVC中的分页和路由
- 如何在ASP.NET MVC中禁用HTTP Keep-Alive?
- ASP.NET Ajax库死了吗?
- asp.net – 用户角色 – 为什么不存储在会话中?
- ASP.net RequiredFieldValidator VisualStudio 2012
- asp.net – 为什么加密一个web配置文件?
- asp.net-mvc – 使用Data Annotation验证DateTime(日期和时
- 嵌套的ASP.NET’应用程序’在IIS内继承父配置值?
- asp.net – IIS 7.5中的Windows身份验证因信任关系异常而失
推荐文章
站长推荐
- asp.net-mvc – ASP.NET MVC – 为基本控制器中的
- asp.net-mvc – 可靠地处理ASP.NET MVC模型绑定错
- ASP.NET vs. Silverlight
- asp.net-mvc – ASP.NET MVC Beta 1 – 哪里是Ht
- asp.net – 迁移匿名配置文件的最佳方式
- ASP.NET将整数绑定到CheckBox的Checked字段
- asp.net-mvc-3 – MVC3重定向到ajax调用后的动作
- asp.net – 错误4005表单身份验证失败 – 提供的
- ASP.net Web服务与WCF
- asp.net-mvc – 使用EF4转换为datetime时发生溢出
热点阅读
