Kendo Grid读取操作不通过.Data方法调用将数据传递给控制器

时间:2014-10-02 15:34:01

标签: razor kendo-ui grid

我有一个Kendo Grid(MVC Razor),我试图通过Read方法的.Data调用将额外数据传递给控制器​​:

   @(Html.Kendo().Grid<AssignedSiteGridPoco>()
        .Name("UnAssignedSiteGrid")
        .Filterable()
        .Sortable()
        .Pageable(pageable => pageable
            .Refresh(true)
            .PageSizes(true)
            .ButtonCount(5))
        .Columns(columns =>
        {
            columns.Bound(p => p.SiteId).Hidden();
            columns.Bound(p => p.SiteName).Title("Site Name").Width(180);
            columns.Bound(p => p.City).Title("City").Width(80);
            columns.Bound(p => p.StateName).Title("State Name").Width(100);
            columns.Command(command => command
                                      .Custom("Add")
                                      .Click("unassignedSiteGridClick")
                           ).Width(90);
        })
        .Scrollable()
        .Selectable(selectable => selectable.Mode(GridSelectionMode.Single))
        .Resizable(resize => resize.Columns(true))
        .Events(events =>
        {
            //events.Change("GridChange");
            //events.DataBound("OnDataBound");
        })
        .DataSource(dataSource => dataSource
            .Ajax()
            .Model(model =>
            {
                model.Id(p => p.SiteId);
                model.Field(p => p.SiteName);
                model.Field(p => p.City).Editable(false);
                model.Field(p => p.StateName).Editable(false);

            })
            .PageSize(15)
            .Read(read => read.Action("GetUnassignedSiteGridDataList",  "Manager").Data("getUserRightName"))

        ))

位于网格div上方的Javascript块如下:

 function getUserRightName() {
      return
      {
          UserRightName : "2"
      };
 }

控制器:

 public JsonResult GetUnassignedSiteGridDataList([DataSourceRequest]DataSourceRequest request, string UserRightName)
{
    var model = new AssignedSiteGridPoco();
    var siteList = _managerPresentationService.GetUnassignedSiteGridDataList(model);
    return Json(siteList.ToDataSourceResult(request));
}

在“UserRightName”字符串中,从视图的read方法传递的字符串值为null。根据示例,它应该传回文本值“2”我的剑道版本是:2014.2.807 InternalBuild。这个领域的这个版本有问题吗?

谢谢, 史蒂芬

1 个答案:

答案 0 :(得分:0)

将json结构中的密钥名称包装成引号,即 将你的js函数更改为:

 function getUserRightName() {
        return {'UserRightName':"2"};
    }