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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Empty Table when binding IEnumerable Datasource

Thread ID:





125248 Aug 2,2016 04:53 PM UTC Aug 17,2016 05:56 AM UTC ASP.NET MVC 7
Tags: Grid
Joe Burke
Asked On August 2, 2016 04:53 PM UTC

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.

Joe Burke
Replied On August 2, 2016 04:58 PM UTC

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

Bill Washburn
Replied On 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")

Ragavee U S [Syncfusion]
Replied On 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. 

Joe Burke
Replied On 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.

Ragavee U S [Syncfusion]
Replied On 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. 

Joe Burke
Replied On August 16, 2016 02:25 PM UTC

That worked. Thanks!

Ragavee U S [Syncfusion]
Replied On August 17, 2016 05:56 AM UTC

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


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon