4
votes

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

2
Visual Studio version? MVC version?Kenan Zahirovic
I am using Visual Studio 2013 Ultimate. MVC is 4.5.1Aindriú
And what version of MVC is the book about?John Saunders
Also, make sure you have the correct assembly referenced. See msdn.microsoft.com/en-us/library/….John Saunders
how do I reference the correct assembly ? Is there not a way that I can install MVC permanently ?Aindriú

2 Answers

7
votes

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.

3
votes

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.