命名空间“System.Web.Mvc”中不存在“Ajax”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26804198/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 10:26:59  来源:igfitidea点击:

'Ajax' does not exist in the namespace 'System.Web.Mvc'

ajaxasp.net-mvcasp.net-mvc-5

提问by Mike van L

I'm new to ASP.NET MVC 5 and I wanted to build a small project to figure some things out. When i opened the project in the browser I got an error saying:

我是 ASP.NET MVC 5 的新手,我想构建一个小项目来解决一些问题。当我在浏览器中打开项目时,我收到一条错误消息:

Compiler Error Message: CS0234: The type or namespace name 'Ajax' does not exist in the namespace 'System.Web.Mvc' (are you missing an assembly reference?)

Source Error:
Line 22:     using System.Web.WebPages; 
Line 23:     using System.Web.Mvc;      
Line 24:     using System.Web.Mvc.Ajax;  
Line 25:     using System.Web.Mvc.Html;  
Line 26:     using System.Web.Routing;

After some googling i found outthat you had to change "Copy Local" to true but i saw that it was already set to true in my project. Even after a clean and a rebuild this error persists.

经过一番谷歌搜索后,我发现您必须将“Copy Local”更改为 true,但我看到它已在我的项目中设置为 true。即使经过清理和重建,此错误仍然存​​在。

So does anyone have an idea about what could cause this error?

那么有没有人知道可能导致此错误的原因?

回答by Ross Bush

I think you are referencing an older version of System.Web. Right-click the project in vs and select 'Manage NuGet Packages' then search for Asp.Net MVC and click install. This will install the proper System.Web with Ajax. You can remove the six other binaries downloaded if they are not needed.

我认为您引用的是旧版本的 System.Web。右键单击 vs 中的项目并选择“管理 NuGet 包”,然后搜索 Asp.Net MVC 并单击安装。这将使用 Ajax 安装正确的 System.Web。如果不需要,您可以删除下载的其他六个二进制文件。

回答by StackticMain

Using MVC 5.2.3, I came across the same issue; it was out of the blue (This error came out of no where without making any changes, as the app was compiling and running smoothly before)

使用 MVC 5.2.3,我遇到了同样的问题;它是出乎意料的(这个错误是在没有做任何更改的情况下突然出现的,因为应用程序之前编译和运行很顺利)

Fix:

使固定:

  • Right-click the Solutionand select "Manage NuGet Packages For Solution"
  • Uninstall the ASP.NET MVC by selecting Uninstallbutton
  • Deselect the Projectthat uses ASP.NET MVC - click Ok
  • Now install ASP.net MVC by finding it in NuGet window under the Online tab and install it for the project it was deselected for previously
  • That should solve the problem as it did for me. Enjoy!
  • 右键单击解决方案并选择“管理解决方案的 NuGet 包
  • 通过选择“卸载”按钮卸载 ASP.NET MVC
  • 取消选择使用 ASP.NET MVC的项目- 单击确定
  • 现在通过在“在线”选项卡下的 NuGet 窗口中找到它来安装 ASP.net MVC,并为之前取消选择的项目安装它
  • 这应该像对我一样解决问题。享受!

回答by Michaja Broertjes

Running Install-Package Microsoft.AspNet.Mvcin the NuGet Package Manager Console did the trick for me.

Install-Package Microsoft.AspNet.Mvc在 NuGet 包管理器控制台中运行对我有用。

回答by Usman Younas

Navigate to References and right click on the system.web.mvc

导航到 References 并右键单击 system.web.mvc

View properties and change Copy Local to True instead of False .

查看属性并将 Copy Local 更改为 True 而不是 False 。

enter image description here

在此处输入图片说明

This did the trick for me in addition to run update package command in Package Manager Console.

除了在包管理器控制台中运行更新包命令之外,这对我有用。

回答by Pavel Nazarov

Set System.Web.MVC CopyLocal as True That helped for me

将 System.Web.MVC CopyLocal 设置为 True 这对我有帮助

回答by Zin Min

Reopen the Visual Studio in Administrator mode.

以管理员模式重新打开 Visual Studio。

回答by ali shalash

I updated the MVC from the NuGet Package Manager Console and solved my problem

我从 NuGet 包管理器控制台更新了 MVC 并解决了我的问题

回答by Sameer Ahmad

Right-click the Solution and select "Manage NuGet Packages For Solution" Uninstall the ASP.NET MVC by selecting Uninstall button Deselect the Project that uses ASP.NET MVC - click Ok Now install ASP.net MVC by finding it in NuGet window under the Online tab and install it for the project it was deselected for previously That should solve the problem as it did for me. Enjoy!

右键单击解决方案并选择“Manage NuGet Packages For Solution”通过选择“卸载”按钮卸载 ASP.NET MVC 取消选择使用 ASP.NET MVC 的项目 - 单击“确定” 现在通过在 NuGet 窗口中找到它来安装 ASP.net MVC Online 选项卡并为之前取消选择的项目安装它这应该可以像对我一样解决问题。享受!