webgrid reference is not found in view

gleasonomicon picture gleasonomicon · Jan 10, 2013 · Viewed 15.4k times · Source

I'm trying to do a basic implementation of the asp.net mvc webgrid mentioned in this tutorial: http://msdn.microsoft.com/en-us/magazine/hh288075.aspx

I'm using asp.net mvc 4.

Upon doing a simple reference to the grid (the first part of the tutorial), I'm getting this error in the view:

Compiler Error Message: CS0246: The type or namespace name 'WebGrid' could not be found (are you missing a using directive or an assembly reference?)

The code for the cshtml file is below:

@model IEnumerable<Company.Core.DataAccess.Models.TransactionLog>
@{
    ViewBag.Title = "Index";
}

@{ 
 var grid = new WebGrid(Model, defaultSort:"TransactionLogId"); 
} 
@grid.GetHtml()

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")  
}

I have a reference to System.Web.Helpers. If I put an @using directive for it in the view, the same message remains. Can anyone help out?

Answer

user1908188 picture user1908188 · Mar 11, 2013
  1. Just add reference to System.Web.Helpers 2.0.0.0 dll which Basic template does not include by default.
  2. After adding the reference, you need to open property for the dll and change Copy Local to True.
  3. Rebuild your project