We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Empty Table when binding IEnumerable Datasource

I am attempting to bind to an IEnumberable Datasource following the example in the documentation. When I do, all I get is an empty table with just the column headers showing.  I know, based on debugger break and output, that the datasource is passed in the Viewbag, but it's not coming out in the html.

My Razor Code:

    @foreach (var item in (IEnumerable<WebApplication1.Areas.Maint.Models.EquipSpendModel>)ViewBag.datasource)

            .Columns(col =>
                col.Field(p => p.Equipment).HeaderText("Equip #").TextAlign(TextAlign.Left).Add();
                col.Field(p => p.EquipDescrip).HeaderText("Description").TextAlign(TextAlign.Left).Add();
                col.Field(p => p.AmountSpend).HeaderText("Amount").TextAlign(TextAlign.Left).Add();

The "foreach" block displays all the Equipment properly. The Grid does not.

7 Replies

JB Joe Burke August 2, 2016 04:58 PM UTC

I just get
"No records to display"
in the table below the column headers.

BW Bill Washburn August 2, 2016 05:40 PM UTC

I just worked on similar
my data source is a list of  "HistActivityRpt'
see the col defs below which work for me
the value header functions look different you might try something like the following

            .Columns(col =>
                col.Field(p => p.StockName).HeaderText("Name").TextAlign(TextAlign.Left).Add();
                col.Field(p => p.StockSymbol).HeaderText("Symbol").TextAlign(TextAlign.Left).Add();
                col.Field(p => p.Activity).HeaderText("Activity").TextAlign(TextAlign.Left).Add();

Hope this helps

            }))                col.Field(p => p.Activity).HeaderText("Activity").TextAlign(TextAlign.Left).Add();                col.Field(p => p.StockSymbol).HeaderText("Symbol").TextAlign(TextAlign.Left).Add();                col.Field(p => p.StockName).HeaderText("Name").TextAlign(TextAlign.Left).Add();            {            .Columns(col =>                                     .AllowSorting()                    .AllowPaging()            .Datasource((IEnumerable<HistActivityRpt>)ViewBag.datasource)@(Html.EJ().Grid<HistActivityRpt>("Grid")

RU Ragavee U S Syncfusion Team August 3, 2016 08:51 AM UTC

Hi Joe, 

We are sorry but we are unable to reproduce the reported issue. We have prepared a grid sample for your reference which can be downloaded from the below location. 

Please try the above sample and if you still face any difficulties, please share the following details. 

1.       Confirm your Essential Studio product version 
2.       Ensure if any script error is thrown in browser console. If so, please share the screenshot of the error. 
3.       First JSON array of the data bound as dataSource. 
4.       Grid rendering code. 
5.       Please reproduce the issue in the above provided sample and share. 

Ragavee U S. 

JB Joe Burke August 3, 2016 01:25 PM UTC

When I look at the JS that is produced, I see this:


So it is expecting to get the data from the DataManager. But I am trying to do local binding. Why is Datamanger being thrown in there?

From the controller, pretty much all I'm doing is this:

var spend = dl.GroupBy(g => new { g.Equipment, g.EquipDescrip }) .Select(n => new Models.EquipSpendModel { Equipment = n.Key.Equipment, EquipDescrip = n.Key.EquipDescrip, AmountSpend = n.Sum(_ => _.Amount) }).OrderBy(s => s.Equipment); ViewBag.datasource = spend.AsEnumerable(); return View();

I loaded the Syncfusion NuGet packages.
No errors in the Chrome developer console.

I'm not sure what I'm doing wrong.

RU Ragavee U S Syncfusion Team August 4, 2016 06:58 AM UTC

Hi Joe, 

Thanks for sharing the requested information. 

We are able to reproduce the reported behavior at our end with the provided code example. The cause of the issue is that you have passed the data as type Linq.DataQuery from controller and have bound it as the grid dataSource. Instead, we suggest you to convert the dataSource to List and then bind it to the grid. Please refer to the below code example. 

public ActionResult Index() 
            var Data = new NorthwindDataContext().OrdersViews.GroupBy(g => new { g.EmployeeID, g.OrderID }) 
                .Select(s => new Models.OrdersView 
                    EmployeeID = s.Key.EmployeeID, 
                    OrderID = s.Key.OrderID, 
                    Freight = s.Sum(d => d.Freight) 
                }).OrderBy(o => o.EmployeeID); 
            ViewBag.dataSource = Data.AsEnumerable().ToList();//convert to list 
            return View(); 

Query: So it is expecting to get the data from the DataManager. But I am trying to do local binding. Why is Datamanger being thrown in there? 

By default, when binding local dataSource such as IEnumerable, DataTable etc., to the grid, it is considered as JSON adaptor type of the DataManager. Please refer to the below documentation. 

Ragavee U S. 

JB Joe Burke August 16, 2016 02:25 PM UTC

That worked. Thanks!

RU Ragavee U S Syncfusion Team August 17, 2016 05:56 AM UTC

Hi Joe, 
Thanks for your update. 
We are happy that your requirement is achieved. 
Ragavee U S. 

Live Chat Icon For mobile
Up arrow icon