Reputation: 151
I am trying to use Grid.MVC to pull from my database into a partial view for another view. I have the following in the Empty View I created in the EditorTemplates:
@{
Layout = null;
}
@using GridMvc.Html
@using Inventory.Entities
@Html.Grid(Model).Columns(columns =>
{
columns.Add().Encoded(false).Sanitized(false).SetWidth(30).RenderValueAs(o => Html.CheckBox("Checked", false));
columns.Add(c => c.ProdName);
columns.Add(c => c.ProdID, true);
})
I have a Controller and for it that is as follows:
using Inventory.Entities;
using Inventory.Web.DataContext;
namespace Inventory.Web.Controllers
{
public class ProductionController : Controller
{
private CommonDB db = new CommonDB();
// GET: Production
public ActionResult Production(string prodGrid)
{
var ProdList = new List<string>();
var ProdQry = from p in db.Productions
select p.ProdName;
ProdList.AddRange(ProdQry.Distinct());
ViewBag.prodGrid = new SelectList(ProdList);
return View(prodGrid);
}
}
}
and the Model is as follows:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
namespace Inventory.Entities
{
public class Production
{
[Key]
public int ProdID { get; set; }
[Required]
public string ProdName { get; set; }
}
}
I have used NuGet package manager to add Grid.MVC to the solution, and have added the following to the _Layout.cshtml after the @Scripts.Render("~/bundles/modernizer"):
<script src="@Url.Content("~/Scripts/jquery.min.js")" type="text/javascript"> </script>
<link href="@Url.Content("~/Content/Gridmvc.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/gridmvc.min.js")" type="text/javascript"> </script>
I checked and there is a reference to GridMVC in the references, along with all the other files that are needed by it. Unfortunately I am having the following errors thrown: Error 1 The type or namespace name 'GridMvc' could not be found (are you missing a using directive or an assembly reference?)
Error 2 'System.Web.Mvc.HtmlHelper' does not contain a definition for 'Grid' and no extension method 'Grid' accepting a first argument of type 'System.Web.Mvc.HtmlHelper' could be found (are you missing a using directive or an assembly reference?)
I have checked the documentation, and various websites trying to figure out what is wrong, but I am stumped. Does anyone see where I might have done something wrong with this? This is now the holdup with my entire project.
Thank you in advance,
Michael Mastro
Upvotes: 0
Views: 5976