This is a migrated thread and some comments may be shown as answers.

[Solved] MVC Grid Binding to Entity Framework

3 Answers 161 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Bob
Top achievements
Rank 1
Bob asked on 07 Nov 2011, 09:34 PM
Ok, day one of trying the grid. 

I am trying to start simple. I want to bind the grid to an EF table and show the data. Well, the grid comes up but I get no data.

I'm using MVC3 with the version of Telerik I get from NuGet. 

The view is pretty simple:

@{
    Html.Telerik().Grid(Model)
        .Name("CompanyGrid")
        .PrefixUrlParameters(false)
        .Pageable()
        .Sortable()
        .Filterable()
        .Render();
}

The index method in the controller is:

public ActionResult Index()
        {
            return View(_context.TransCommons);
        }

The grid shows up, but there is no data in it. 

BOb

3 Answers, 1 is accepted

Sort by
0
Georgi Tunev
Telerik team
answered on 08 Nov 2011, 10:33 AM
Hello Bob,

Could you please check if _context.TransCommons actually contains data? The grid will not show any data if the result set is empty.


Regards,
Georgi Tunev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
Bob
Top achievements
Rank 1
answered on 08 Nov 2011, 03:42 PM
Yes, the table has about 300k rows in it. 

I got it to work.. not sure what I was doing wrong.

BTW: Does this work with non strongly typed views? I got an error when I didn't add the @model declaration to the view. I figure maybe I have to cast model somehow?

BOb
0
Georgi Tunev
Telerik team
answered on 09 Nov 2011, 03:38 PM
Hi again Bob,

 Generally speaking, you should either specify @model or as an alternative - cast the Model property (i.e. @{Html.Telerik().Grid((IEnumerable<T>)Model) )


Kind regards,
Georgi Tunev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
Tags
Grid
Asked by
Bob
Top achievements
Rank 1
Answers by
Georgi Tunev
Telerik team
Bob
Top achievements
Rank 1
Share this question
or