Unable to get data into kendo grid

2 posts, 0 answers
  1. Scott
    Scott avatar
    1 posts
    Member since:
    Oct 2015

    Posted 24 Nov 2015 Link to this post

     Hello, I am unable to get data into my kendo grid. I have looked at many other threads but nothing has helped so far. I want to get the data from my controller / model but I am not sure if i am trying to do it correctly
     

     VIEW

    @model MyProject.Models.POApprovalViewModel 
     
    @{
        Layout = "~/Views/Shared/_Layout.cshtml";
    }
     
    @{
        ViewBag.Title = "PO Approval";
    }
     
    <div class="container">
        <h4>PO Approval</h4>     
     
        @(Html.Kendo().Grid(Model.AssignedApprovals)
                  .Name("grdPOs")
                  .Columns(columns =>
                  {
                      columns.Bound(model => model.PoId);
                      columns.Bound(model => model.PoStatus);
                  })
                  .Pageable()
                  .Sortable()
                  .DataSource(dataSource => dataSource
                      .Ajax()
                      .ServerOperation(true)
                      .Model(model => model.Id("PoId"))
                      .Read(read => read.Action("POApproval_Read", "POApproval"))
                   )
        )
     
    </div>

     

     CONTROLLER

    public class POApprovalController : Controller
    {
        string UserId;
        POApprovalViewModel po;
     
        // GET: POApproval
        public ActionResult Index()
        {
            po = new POApprovalViewModel();
            return View(po);
        }
     
        [HttpPost]
        public ActionResult POApproval_Read()
        {
            dbPOApproval db = new dbPOApproval();
            return Json(db.GetAssignedApprovals());
        }
    }

     

    MODEL

        public class POApprovalViewModel
       {
           public List<OLAssignedApprovals> AssignedApprovals
           {
               get
               {
                   if (_AssignedApprovals == null)
                   {
                       _AssignedApprovals = new List<OLAssignedApprovals>();
                   }
                   return _AssignedApprovals;
               }
           }
     
           private List<OLAssignedApprovals> _AssignedApprovals;
       }   
     
       public class OLAssignedApprovals
       {
           public int PoId { get; set; }
           public string PoStatus { get; set; }
       }
     
       public class dbPOApproval
       {
           MyDataSourceOjbect objPOApproval = new MyDataSourceOjbect();
     
           public List<Models.OLAssignedApprovals> GetAssignedApprovals()       
           {
               List<Models.OLAssignedApprovals> lPoApproval = new List<Models.OLAssignedApprovals>();
               Models.OLAssignedApprovals li = new Models.OLAssignedApprovals();
     
               DataSet ds = objPOApproval.GetPOApprovals();
     
               foreach (DataRow dr in ds.Tables[0].Rows)
               {
                   li = new Models.OLAssignedApprovals();
                   li.PoId = Convert.ToInt32(dr["POID"]);
                   li.PoStatus = dr["POStatus"].ToString();
     
                   lPoApproval.Add(li);
               }
     
     
               return lPoApproval;
           }
       }

  2. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2153 posts

    Posted 25 Nov 2015 Link to this post

    Hello Scott,

    Could you specify how would you like to populate the Grid data - locally by passing a Model collection or remotely by using a read action? The current one is a mix of both, which is used in rare cases.

    Regards,
    Dimiter Madjarov
    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
Back to Top