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

No data displayed

3 Answers 130 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Harald
Top achievements
Rank 2
Harald asked on 01 Nov 2015, 10:58 AM

Controllercode:

01.namespace vEF_AspApplication.Controllers
02.{
03.    public class AddressesController : Controller
04.    {
05.        private MyDataModelContext db = new MyDataModelContext();
06. 
07.        // GET: Addresses
08.        public async Task<ActionResult> Index()
09.        {
10.            var addresses = db.Addresses.Include(a => a.FormOfAddress).Include(a => a.Title);
11.            return View(await addresses.ToListAsync());
12.        }
13.    }
14.}

Viewcode:

01.@(Html.Kendo().MobileView()
02.    .Title("EntityFramework DataAccess")
03.    .Name("Index")
04.    .Content(@<text>
05.        <div id="AddressList">
06.          @(Html.Kendo().Grid<vEF_Library.Address>()
07.          .Name("AddressGrid")
08.          .Columns(columns =>
09.              {
10.                  columns.Bound(c => c.LastName);
11.                  columns.Bound(c => c.FirstName);
12.                  columns.Bound(c => c.Phone);
13.              })
14.                .HtmlAttributes(new { style = "height: 100%;" })
15.                .HtmlAttributes(new { style = "width: 100%;" })
16.                .Scrollable()
17.                //.Groupable()
18.                .Sortable()
19.                .Pageable(pageable => pageable
20.                .Refresh(true)
21.                .PageSizes(true)
22.                .ButtonCount(10))
23.                .DataSource(dataSource => dataSource
24.                .Ajax()
25.                .Read(read => read.Action("Index", "Addresses"))
26.                )
27.            )
28.        </div>
29.    </text>)
30.)

What is wrong?

3 Answers, 1 is accepted

Sort by
0
Alexander Popov
Telerik team
answered on 03 Nov 2015, 10:25 AM
Hi Herald,

The Controller method should return a properly formatted JSON string. Please check the Grid Ajax binding article for more details on that subject.

Regards,
Alexander Popov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Harald
Top achievements
Rank 2
answered on 07 Nov 2015, 04:14 PM

I have adapted the code from the example, but no data displayed.

Viewcode:

01.@(Html.Kendo().MobileView()
02.        .Title("EntityFramework DataAccess")
03.    .Name("Index")
04.    .Content(@<text>
05. 
06.        @(Html.Kendo().Grid<vEF_Library.Address>()
07.      .Name("grid")
08.      .DataSource(dataSource => dataSource // Configure the grid data source
09.          .Ajax() // Specify that ajax binding is used
10.          .Read(read => read.Action("Products_Read", "Home")) // Set the action method which will return the data in JSON format
11.       )
12.      .Columns(columns =>
13.      {
14.          // Create a column bound to the ProductID property
15.          columns.Bound(address => address.LastName);
16.          // Create a column bound to the ProductName property
17.          columns.Bound(address => address.FirstName);
18.          // Create a column bound to the UnitsInStock property
19.          columns.Bound(address => address.Phone);
20.      })
21.      .Pageable() // Enable paging
22.      .Sortable() // Enable sorting
23.        )
24.    </text>)
25.)

 Controllercode:

01.namespace vEF_AspApplication.Controllers
02.{
03.    public class HomeController : Controller
04.    {
05.        public ActionResult Products_Read([DataSourceRequest]DataSourceRequest request)
06.        {
07.            using (var db = new vEF_Library.MyDataModelContext())
08.            {
09.                IQueryable<Address> products = db.Addresses;
10.                DataSourceResult result = products.ToDataSourceResult(request);          
11.                return Json(result);
12.            }
13.        }
14.    }
15.}

Results, see attached screenshots.

 

 

0
Accepted
Alexander Popov
Telerik team
answered on 11 Nov 2015, 07:48 AM
Hello Harald,

The code you shared seems correct, so I suspect that the kendo.aspnetmvc.min.js file is not included. Would you please verify that and also check the browser's console for any error messages that might give us a hint?

Regards,
Alexander Popov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Harald
Top achievements
Rank 2
Answers by
Alexander Popov
Telerik team
Harald
Top achievements
Rank 2
Share this question
or