Abdul Hameed
Abdul Hameed

Reputation: 11

Gridmvccore not showing any data in table?

I am using Nonfactors.Grid.Mvc(6.2.4) and trying to show data in table. I have also included styles and js file in layout as well, But data is not showing , even table is now showing.

View

@using NonFactors.Mvc.Grid
@model IQueryable<Student>
@{

ViewBag.Title = "Students List";
 }
    <div class="panel">

        <div class="panel-body">
            @(Html
 .Grid(Model)
 .Build(columns =>
 {
     columns.Add(model => model.Name).Titled("Name");
     columns.Add(model => model.Address).Titled("Surname");
     columns.Add(model => model.Email).Titled("Marital status");

     columns.Add(model => model.GPA).Titled("Age");
     columns.Add(model => model.Major).Titled("Birthday");
     columns.Add(model => model.Minor).Titled("Employed");
 })
 .Empty("No data found")
 .Filterable()
 .Sortable()
 .Pageable()
 )
        </div>

Controller method

   [HttpGet]
    public ViewResult LoadStudents()
    {
        List<Student> students = (from Student in this.Context.Students
                                  select Student).ToList();
        var queryable = students.AsQueryable();// i debug and see data is populating in this

        return View(Context.Set<Student>());

    }

I also use inspect element and check console errors but no error showing as well. I have install gridmvc through package manager. No error showing, even build successfully but no data is showing,

Upvotes: 0

Views: 1153

Answers (2)

MohammadSoori
MohammadSoori

Reputation: 2408

You should following steps in below link: https://aspnet-core-grid.azurewebsites.net/installation

Consider the steps of the photo while reading.

  1. afetr install from nuget, goto your user profile folder and following path .nuget\packages\NonFactors.Grid.Mvc6
    in your project you should be have structure same solution explorer(like photo) in photo. find files in presented path and copy to created folders.
  2. add css and js to your main page (for me: index.html).
  3. use grid extensions namespaces (@using NonFactors.Mvc.Grid) in partial view (for me: _indexGrid.html)
  4. and the end add below code to script tag, after included mvc-grid.js

document.querySelectorAll(".mvc-grid").forEach(element => new MvcGrid(element));

enter image description here

Upvotes: 0

Jerry Cai
Jerry Cai

Reputation: 949

Do you use asp.net core mvc or asp.net mvc?

Nonfactors.Grid.Mvc(6.2.4) is for ASP.NET MVC projects.

Make sure the script is correctly referred.

If you using asp.net mvc, you can also try Grid.Mvc, it can work on my site:

https://www.codeproject.com/Tips/597253/Using-the-Grid-MVC-in-ASP-NET-MVC

Result like:

enter image description here

Upvotes: 0

Related Questions