使用Web API 2的Kendo Grid MVC服务器端包装器

时间:2014-07-03 15:42:59

标签: asp.net-mvc kendo-ui

我使用Web API设置了Kendo Grid和MVC服务器端包装器。这是我在视图中的代码

 @(Html.Kendo().Grid<Models.UserViewModel>()
          .Name("UserGrid")
          .Columns(column =>
          {
              column.Bound(c => c.FirstName);
              column.Bound(c => c.LastName);
              column.Bound(c => c.Email);
          })
          .DataSource(ds => ds
                .Ajax()
                .Model(m => m.Id(u => u.Id))
                .Read(read => read.Url("/api/..").Type(HttpVerbs.Get))

          )
    )

这是我的web api控制器,我发现它的问题是我得到null是请求参数。我不确定为什么会这样,请给我任何建议

public DataSourceResult GetAllUsers
            ([ModelBinder(typeof(DataSourceRequestModelBinder))] DataSourceRequest request)
        {
            var users= _userRepository.GetAllUsers();
            return users.ToDataSourceResult(request, s => new UserViewModel
            {
                Id = s.Id,
                FirstName = s.FirstName,
                LastName = s.LastName,
                Email = s.Email

            });
        }

1 个答案:

答案 0 :(得分:0)

我打赌你需要允许使用你的控制器方法:

public DataSourceResult GetAllUsers
            ([ModelBinder(typeof(DataSourceRequestModelBinder))] DataSourceRequest request)
        {
            var users= _userRepository.GetAllUsers();
            return users.ToDataSourceResult(request, s => new UserViewModel
            {
                Id = s.Id,
                FirstName = s.FirstName,
                LastName = s.LastName,
                Email = s.Email

            }).JsonRequestBehavior.AllowGet;
        }