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

Unable to get data into kendo grid

1 Answer 96 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Scott
Top achievements
Rank 1
Scott asked on 24 Nov 2015, 08:23 PM
 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;
       }
   }

1 Answer, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 25 Nov 2015, 09:03 AM

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
Tags
Grid
Asked by
Scott
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
Share this question
or