0

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

3
  • Did you check the <pages section in the web.config files inside root and views folders. These should have the namespace liates Commented Mar 14, 2015 at 17:22
  • It is in the web.config of the root folder. it shows: <pages> <namespaces> <add namespace="GridMvc" /> </namespaces> </pages> Commented Mar 15, 2015 at 1:41
  • I'm guessing one or more js files are not rendering correctly. If you run the page and hit f12, can you verify the the scripts are actually there? Commented Jun 16, 2015 at 21:36

1 Answer 1

2

Try adding

@using NonFactors.Mvc.Grid

statement if your view.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks that was part of the problem. The other part was even though I grabbed the files from NuGet, they were not copied over to the right directory.
Awesome bro! this was just the prob. You solved it simple well. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.