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

Kendo grid not rendering

7 Answers 381 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Palanisamy
Top achievements
Rank 1
Palanisamy asked on 18 Sep 2015, 02:08 PM

Please see my below code in cshtml and controller

cshtml

--------------

@{
    ViewBag.Title = "KendoGrid";
}

@using Kendo.Mvc.UI
<html>
<head>
    <link href="~/Content/kendo.common.min.css" rel="stylesheet" />
    <link href="~/Content/kendo.default.min.css" rel="stylesheet" />
    <script src="~/Scripts/jquery-1.10.2.min.js"></script>
    <script src="~/Scripts/kendo.all.min.js"></script>
    <title></title>
</head>
<body>

    @(Html.Kendo().Grid<KendogridTestPoc.Models.MasterClient>()
    .Name("grid")
    .Columns(columns =>
    {
        columns.Bound(o => o.MasterClientID).Width(110);
        columns.Bound(o => o.MasterName).Width(130);
    })
    //.ToolBar(toolbar => toolbar.Create())
    //.Editable(editable => editable.Mode(GridEditMode.PopUp)) // Use inline editing mode
    .Sortable()
    .Pageable()
    .HtmlAttributes(new { style = "height:430px;" })
    .DataSource(dataSource => dataSource
        .Ajax()
        .PageSize(100)
        .Model(model => model.Id(p => p.MasterClientID))
           .Read(read => read.Action("GettblMasterClients", "Home"))
     )
    )
</body>
</html>    

Controller

------------------------

using Kendo.Mvc.Extensions;
using Kendo.Mvc.UI;
using KendogridTestPoc.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace KendogridTestPoc.Controllers
{
    public class HomeController : Controller
    {
        private readonly List<MasterClient> masterClients;

        public HomeController()
        {
            masterClients = new List<MasterClient>();
            masterClients.AddRange(new MasterClient[] {
                new MasterClient()
                {
                   MasterClientID = 3001,
                   MasterName="TestFiserv"
                },
                new MasterClient()
                {
                    MasterClientID = 3002,
                   MasterName="TestDefenders"
                }
            });
        }

        public ActionResult GettblMasterClients()
        {
            return Json(masterClients,JsonRequestBehavior.AllowGet);
        }
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }

        public ActionResult KendoGrid()
        {
            MasterClient ms = new MasterClient();
                ms.MasterClientID = 121;
            ms.MasterName = "Test";
            return View(ms);
        }

    }
}​​

7 Answers, 1 is accepted

Sort by
0
Blake
Top achievements
Rank 2
answered on 18 Sep 2015, 03:11 PM

In your controller, include these references

using Kendo.Mvc.UI;
using Kendo.Mvc.Extensions;

and try changing your method to this

public ActionResult GettblMasterClients([DataSourceRequest] DataSourceRequest dsRequest)
{
    return Json(masterClients.ToDataSourceResult(dsRequest));
}

0
Palanisamy
Top achievements
Rank 1
answered on 19 Sep 2015, 06:44 AM

Hi,

 Could not change.Since masterclients is a generic list.I dont have option to convert todatasourceresult even after adding namespaces.kindly help me with other solution.

0
Palanisamy
Top achievements
Rank 1
answered on 21 Sep 2015, 06:08 AM
Thanks now i got the result
0
Blake
Top achievements
Rank 2
answered on 21 Sep 2015, 12:02 PM
Would you mind posting the solution for future reference?
0
Palanisamy
Top achievements
Rank 1
answered on 21 Sep 2015, 01:18 PM
Yes. Why not. Cant we do that? You guys are really helpful. Thats y i am asking my all doubts. Is it disturbance for you?
0
Blake
Top achievements
Rank 2
answered on 21 Sep 2015, 01:26 PM
No it is not a disturbance, just curious myself as to what your solution to this problem was. I also think that your solution may help others fix similar problems in the future.
0
Palanisamy
Top achievements
Rank 1
answered on 21 Sep 2015, 01:36 PM
OK cool thanks. I will give my solution once done. Its in progress.
Tags
Grid
Asked by
Palanisamy
Top achievements
Rank 1
Answers by
Blake
Top achievements
Rank 2
Palanisamy
Top achievements
Rank 1
Share this question
or