Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

asp.net-mvc

I am trying out examples from a book. The first one is really simple .. a few lines of code in a view (MVC).

I run the code but get an error :

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

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;

Source File: c:\Users\Aindriu\AppData\Local\Temp\Temporary ASP.NET Files\root\6882868f\b519e811\App_Web_index.cshtml.a8d08dba.h-o4pos5.0.cs    Line: 24 

I fixed the problem - I right clicked the solution in Solution Properties (on the right) and selected Manage Nuget Packages - i typed in MVC on top right search bar - and installed MVC.... it installed a whole load of files and my program worked..... but it added code to the solution I am working on..

Is there a easy way to get around this error ? I don't want to have to keep doing this every time I create a MVC program...

like image 627
Aindriú Avatar asked Dec 25 '22 00:12

Aindriú


2 Answers

If you are using Visual Studio, from the project's References select the System.Web.Mvc dll. At the Properties Window set the Copy Local attribute to True.

You could even copy the necessary references to the bin\Debug or bin\Release directory (whichever you would use) manually, but setting it to happen automatically by Visual Studio is far better.

like image 122
aniski Avatar answered Feb 19 '23 14:02

aniski


With newer versions of MVC, the preferred method is to use the NuGet package manager. Under: View > Other Windows > Package Manager Console. Type:

Install-Package Microsoft.AspNet.Mvc -Version 4.5.1

You should do this for every Mvc project.

like image 39
beautifulcoder Avatar answered Feb 19 '23 14:02

beautifulcoder