c# - TypeError: this.model.currentViewData is undefined (In Implimentation of Hierarchical Grid --> Child Grid) -


i implementing hierarchy grid in asp.net mvc using syncfusion grid control. fetching data server side ajax call on expansion of child grid. when try expand child grid, ajax call fetches data in json format , javascript error (typeerror: this.model.currentviewdata undefined) occurs , data in child grid doesn't load child grid. details of question , running source code example available here.

classes

 public class data {     public int orderid { get; set; }     public int employeeid { get; set; }     public string shipcountry { get; set; }     public list<childdata> employee { get; set; } } public class childdata {     public int employeeid { get; set; }     public string firstname { get; set; }     public string lastname { get; set; } } 

controller

    public class gridcontroller : controller {     //     // get: /grid/     list<data> obj = new list<data>();       public actionresult gridfeatures()     {          var datasource = getdata();         viewbag.datasource = datasource.tolist();         return view();     }     public jsonresult getchilddata(int _empid)     {         var childdaqtasource = childdata(_empid);         return json(childdaqtasource, jsonrequestbehavior.allowget);     }      public static list<data> getdata()     {          list<data> obj = new list<data>();         //obj.add(new data() { orderid = 1000, employeeid = 1, shipcountry = "india", employee = new list<childdata>() { new childdata() { employeeid = 1, firstname = "janet", lastname = "david" } } });         //obj.add(new data() { orderid = 1001, employeeid = 2, shipcountry = "france", employee = new list<childdata>() { new childdata() { employeeid = 2, firstname = "nancy", lastname = "john" } } });         //obj.add(new data() { orderid = 1002, employeeid = 3, shipcountry = "us", employee = new list<childdata>() { new childdata() { employeeid = 3, firstname = "david", lastname = "staven" } } });         //obj.add(new data() { orderid = 1003, employeeid = 4, shipcountry = "us", employee = new list<childdata>() { new childdata() { employeeid = 4, firstname = "janet", lastname = "david" } } });          obj.add(new data() { orderid = 1000, employeeid = 1, shipcountry = "india" });         obj.add(new data() { orderid = 1001, employeeid = 2, shipcountry = "france"  });         obj.add(new data() { orderid = 1002, employeeid = 3, shipcountry = "us"  });         obj.add(new data() { orderid = 1003, employeeid = 4, shipcountry = "us" });         return obj;      }     public static list<childdata> childdata(int _empid)     {         list<childdata> _childdata = new list<childdata>();         _childdata.add(new childdata { employeeid = 1, firstname = "john", lastname = "freeman" });         _childdata.add(new childdata { employeeid = 1, firstname = "steve", lastname = "alexander" });         _childdata.add(new childdata { employeeid = 1, firstname = "ali", lastname = "naeem" });         _childdata.add(new childdata { employeeid = 1, firstname = "alex", lastname = "wonder" });         _childdata.add(new childdata { employeeid = 1, firstname = "bill", lastname = "gates" });         _childdata.add(new childdata { employeeid = 1, firstname = "alan", lastname = "turing" });          _childdata.add(new childdata { employeeid = 2, firstname = "mark", lastname = "anthoney" });         _childdata.add(new childdata { employeeid = 2, firstname = "carl", lastname = "shoemaker" });         _childdata.add(new childdata { employeeid = 3, firstname = "carlos", lastname = "anthony" });         return _childdata.where(x => x.employeeid == _empid).tolist();     } } 

razor view (gridfeatures.cshtml)

@model  list<remotesaveadaptorsample.controllers.data> <h2>requisitions</h2> @(html.ej().grid<remotesaveadaptorsample.controllers.data>("employeegrid")     .datasource((list<remotesaveadaptorsample.controllers.data>)viewbag.datasource)     //.datasource(model)     .allowsorting(true)     .allowresizing(true)     .allowpaging(true)     .allowgrouping(true)     .allowtextwrap(true)     .allowscrolling(true)     .allowfiltering()     .enablerowhover(true)     .columns(col =>     {         col.field(x => x.employeeid).headertext("employeeid").width(30).isprimarykey(true).allowresizing(false).add();         col.field(x => x.orderid).headertext("orderid").width(60).allowfiltering(true).add();         col.field(x => x.shipcountry).headertext("country").width(100).add();      })     .childgrid     //<remotesaveadaptorsample.controllers.childdata>     (_childgrid =>     {         _childgrid         .querystring("employeeid")         .allowpaging()         .columns(_childcol =>         {             _childcol.field("employeeid").headertext("employeeid").add();             _childcol.field("firstname").headertext("first name").add();         })         .clientsideevents(x => x.load("loadevent"))         ;     }) ) <script type="text/javascript">     function loadevent(args) {         var data = this.model.parentdetails.parentkeyfieldvalue;         this.model.datasource = ej.datamanager({             url: "/grid/getchilddata?_empid=" + data + ""             , adaptor: "urladaptor"         });     } </script> 

any appriciated

thanx

i have checked query , found have returned result alone server side instead of passing result , count pair. when using urladaptor must return data result , count pair. bind data grid.

refer code example

 public jsonresult getchilddata(int _empid)     {         var childdaqtasource = childdata(_empid);         var count = childdaqtasource.count;         return json(new { result = childdaqtasource, count = count });       } 

refer documentation link of urladaptor link: https://help.syncfusion.com/aspnetmvc/grid/data-adaptors#url-adaptor


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -