J.O*_*sen 216 c# asp.net-mvc-3
推出MVC3解决方案进展顺利,但在浏览器中出错:
编译器错误消息:CS0234:命名空间"System.Web.Mvc"中不存在类型或命名空间名称"Html"(您是否缺少程序集引用?)
Source Error:
Line 25: <add namespace="System.Web.Mvc" />
Line 26: <!--<add namespace="System.Web.Mvc.Ajax" />-->
Line 27: <add namespace="System.Web.Mvc.Html" />
Line 28: <add namespace="System.Web.Routing" />
Line 29: <add namespace="System.Web.WebPages" />
Run Code Online (Sandbox Code Playgroud)
我已经NuGet为所有项目安装了解决方案包并设置了MVC3.是否MVC3包括图书馆System.Web.Mvc.Ajax, System.Web.Mvc.Html和其他人呢?为什么我收到错误?
在References文件夹中,我有System.Web.Mvc
Runtime version: v4.0.30319,
Version: 3.0.0.0
Run Code Online (Sandbox Code Playgroud)
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=152368
-->
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
<add key="webpages:Version" value="1.0.0.0" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="2880" />
</authentication>
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
</namespaces>
</pages>
<httpRuntime targetFramework="4.5" encoderType="System.Web.Security.AntiXss.AntiXssEncoder, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<machineKey compatibilityMode="Framework45" />
<profile defaultProvider="DefaultProfileProvider">
<providers>
<add name="DefaultProfileProvider" type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
</providers>
</profile>
<membership defaultProvider="DefaultMembershipProvider">
<providers>
<add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
</providers>
</membership>
<roleManager defaultProvider="DefaultRoleProvider">
<providers>
<add name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
</providers>
</roleManager>
<sessionState mode="InProc" customProvider="DefaultSessionProvider">
<providers>
<add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" />
</providers>
</sessionState>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
</entityFramework>
<connectionStrings>
<add name="EFDbContext" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=SportStore;Integrated Security=True;Pooling=False;" providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
Run Code Online (Sandbox Code Playgroud)
MSDN System.Web.Mvc命名空间
档案packages.config:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EntityFramework" version="5.0.0-rc" />
<package id="jQuery" version="1.7.2" />
<package id="jQuery.UI.Combined" version="1.8.11" />
<package id="jQuery.Validation" version="1.9" />
<package id="Microsoft.AspNet.Mvc" version="3.0.20105.1" />
<package id="Microsoft.AspNet.Providers.Core" version="1.0" />
<package id="Microsoft.AspNet.Providers.LocalDB" version="1.0" />
<package id="Microsoft.AspNet.Razor" version="1.0.20105.408" />
<package id="Microsoft.AspNet.WebPages" version="1.0.20105.408" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" />
<package id="Modernizr" version="2.0.6" />
<package id="Moq" version="4.0.10827" />
<package id="Ninject" version="3.0.1.10" />
</packages>
Run Code Online (Sandbox Code Playgroud)
Tof*_*fee 419
清理您的解决方案,然后将这些文件的属性设置为Copy Local = True.
将"复制本地"属性设置为"True"或"False"
在Solution Explorer中,单击Show All Files按钮以显示References节点.
Chr*_*ris 60
无论出于何种原因,我的两个解决方案都有Web项目,这些项目会以某种方式自动卸载asp.net MVC.我从Nuget安装它,现在它们都再次工作.这发生在最近一批Windows更新之后,其中包括我正在使用的版本的.net框架更新(4.5.1).
编辑:来自.Net Web开发和工具博客:
微软Asp.Net MVC安全更新MS14-059打破了我的构建!
Bla*_*Spy 38
当我从IIS运行时,这个通常会抓住我,默认站点的应用程序池设置为.NET 2.0版.从visual studio使用IIS时,它会创建一个虚拟目录,但仍然在默认站点的应用程序池下运行.如果在Web服务器中使用内置版本,请右键单击您的Web项目,转到属性并确保在正确的.NET版本下运行它.在IIS上,检查应用程序池上的.NET版本.
继我上一篇关于如何创建项目的评论之后 - 您是否正确包含程序集,如下所示(取自VS10中MVC3项目模板生成的默认web.config文件):
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
Run Code Online (Sandbox Code Playgroud)
Mat*_*att 30
您需要更新MVC.
Pet*_*ngs 28
我遇到了同样的问题 - 我的情况是我从lib文件夹引用了新的System.Web.Mvc.dll而我没有将"Copy Local"设置为true.然后应用程序恢复到GAC中的版本,该版本中没有正确的命名空间(Html,Ajax等)并且给了我运行时错误.
aza*_*rc3 16
我的解决方案是在管理Nuget软件包解决方案下... - 我已经为很多软件包做了很多更新.
让我支持半步并说我搞砸了自己,因为我将解决方案和项目从一个文件夹转移到另一个文件夹......所以事情已经完成了与项目所考虑的事情相比的问题.一切都移动得很好,但显然Nuget变得困惑,除非你使用与我不同的方法.
回到解决方案......我只是去管理Nuget Packages for Solution ... >> 更新 >> Microsoft和.NET并点击Update All按钮.
一切都恢复正常和快乐.
我下载了一个mvc 5项目和指向的违规问题
<add namespace="System.Web.Mvc.Ajax" />
Run Code Online (Sandbox Code Playgroud)
有这个错误消息:
CS0234: The type or namespace name 'Ajax' does not exist in the namespace 'System.Web.Mvc' (are you missing an assembly reference?)
Run Code Online (Sandbox Code Playgroud)
- >我来到这个网页并尝试了一些干净的东西等等......
对我有用的只是
Manage Nuget and Update all the packages. Then it worked fine.
Run Code Online (Sandbox Code Playgroud)
在nuget包管理器中运行以下命令为我修复了它:
update-package microsoft.aspnet.mvc -reinstall
Run Code Online (Sandbox Code Playgroud)
小智 6
考虑到问题日期,这个答案相当晚,但有人可能会觉得它很有用.
在本地项目Net Framework 4.5 MVC 4中,上述解决方案都不适用于Visual Studio 2012.对于上下文,我正在遵循有关在CodeProject上创建准系统Web Api的教程(http://www.codeproject.com/)文章/ 615805/Creating-a-Clean-Minimal-Footprint-ASP-NET-WebAPI)当我遇到这个问题时.
对我来说有用的是明确地将"System.Web.Mvc"添加到我的应用程序的引用中,即使该应用程序已经引用了"System.Web".
| 归档时间: |
|
| 查看次数: |
359596 次 |
| 最近记录: |