TypeError:this.model.currentViewData未定义(在层次网格的Implimentation中 - >子网格)

时间:2017-09-12 05:36:31

标签: c# jquery ajax asp.net-mvc syncfusion

我正在使用syncfusion网格控件在ASP.Net MVC中实现层次结构网格。 我从服务器端获取数据,并在子网格的扩展上调用ajax。当我尝试扩展子网格时,ajax调用以JSON格式提取数据,并且发生JavaScript错误(TypeError:this.model.currentViewData未定义),并且子网格中的数据不会加载到子网格中。 问题和运行源代码示例的详细信息也可用here

 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; }
}

控制器

    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>

任何帮助都是适当的

感谢名单

1 个答案:

答案 0 :(得分:1)

我检查了查询,发现您已从服务器端单独返回结果,而不是将其作为结果和计数对传递。使用UrlAdaptor时,必须将数据作为结果和计数对返回。这样它就会将数据绑定到网格中。

参考代码示例

 public JsonResult GetChildData(int _empID)
    {
        var ChildDaqtaSource = ChildData(_empID);
        var count = ChildDaqtaSource.Count;
        return Json(new { result = ChildDaqtaSource, count = count }); 
     }

请参阅UrlAdaptor的文档链接 链接:https://help.syncfusion.com/aspnetmvc/grid/data-adaptors#url-adaptor