Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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:

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 out that 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.

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

like image 210
Mike van L Avatar asked Nov 07 '14 15:11

Mike van L


2 Answers

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.

like image 87
Ross Bush Avatar answered Oct 21 '22 09:10

Ross Bush


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)

Fix:

  • 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!
like image 17
StackticMain Avatar answered Oct 21 '22 09:10

StackticMain