No data displayed

4 posts, 1 answers
  1. Harald
    Harald avatar
    48 posts
    Member since:
    Oct 2013

    Posted 01 Nov 2015 Link to this post

    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?

  2. Alexander Popov
    Admin
    Alexander Popov avatar
    1416 posts

    Posted 03 Nov 2015 Link to this post

    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
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Harald
    Harald avatar
    48 posts
    Member since:
    Oct 2013

    Posted 07 Nov 2015 Link to this post

    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.

     

     

  5. Answer
    Alexander Popov
    Admin
    Alexander Popov avatar
    1416 posts

    Posted 11 Nov 2015 Link to this post

    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
Back to Top
UI for ASP.NET MVC is VS 2017 Ready