asp.net-mvc 类型或命名空间名称“Mvc”不存在

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22325964/
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-08 03:35:09  来源:igfitidea点击:

The type or namespace name 'Mvc' does not exist

asp.net-mvcvisual-studio-2013

提问by s.k.paul

I have recently installed visual studio 2013. After downloaded a sample project from web, while i run it, it gives me the following errors-

我最近安装了 Visual Studio 2013。从网上下载了一个示例项目后,当我运行它时,它给了我以下错误-

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

How to overcome this error?

如何克服这个错误?

回答by Andrei V

The source of your error may be that you do not have a reference to the MVC framework library. A simple solution is to add this reference trough Nuget. The MVC library will be installed in your bindirectory and, if needed, all the references will be added to your project.

您的错误来源可能是您没有对 MVC 框架库的引用。一个简单的解决方案是通过 Nuget 添加此引用槽。MVC 库将安装在您的bin目录中,如果需要,所有引用都将添加到您的项目中。

Either browse for the MVC package (Tools -> Nuget Package Manager -> Manage Nuget Packages for Solution) or install it using the Nuget console (Tools -> Nuget Package Manager -> Package Manager Console) by entering Install-Package Microsoft.AspNet.Mvc. You can find additional information on the official Nuget page for AspNet.Mvc.

无论是浏览的MVC包(工具- > NuGet包管理器- >管理的NuGet包解决方案),或使用的NuGet控制台安装(工具- > NuGet包管理器- >程序包管理器控制台)输入Install-Package Microsoft.AspNet.Mvc。您可以在AspNet.Mvc官方 Nuget 页面上找到更多信息。

回答by Jason Evans

My solution was to simply open up the nuget package manager console and run the command update-package -reinstall Microsoft.AspNet.Mvc

我的解决方案是简单地打开 nuget 包管理器控制台并运行命令 update-package -reinstall Microsoft.AspNet.Mvc

回答by noobprogrammer

Sometimes the package version conflict becomes an issue where if you have the MVC package installed then it shows the namespace error.

有时,包版本冲突会成为一个问题,如果您安装了 MVC 包,则会显示命名空间错误。

Here is how I solved it:

这是我解决它的方法:

  • Open Package Manager Console (Tools > NuGet Package Manager > Package Manager Console)
  • Type uninstall-package Microsoft.AspNet.Mvc
  • Type install-package Microsoft.AspNet.Mvc
  • 打开包管理器控制台(工具 > NuGet 包管理器 > 包管理器控制台)
  • 键入卸载包 Microsoft.AspNet.Mvc
  • 键入安装包 Microsoft.AspNet.Mvc

So this will give your package a fresh start, you will have all new MVC references and no errors.

因此,这将使您的包重新开始,您将拥有所有新的 MVC 引用并且没有错误。