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

WebApi Controller Datarequest coming as null

2 Answers 139 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Manoj
Top achievements
Rank 1
Manoj asked on 07 Aug 2013, 02:37 PM
Hi,

I'm trying to bind the grid with a call from WebApi controller based on the project described in this blog post http://www.kendoui.com/blogs/teamblog/posts/12-11-29/the_facts_on_using_kendo_ui_with_asp_net_webapi.aspx . It's actually hitting the method in ApiContoller but the dataRequest is coming as null from and it's never hitting the ModelBinder code.

Code snippets from cshtml and controller are below:
cshtml:
  @(Html.Kendo().Grid<ABC>()
                          .Name("grdEngagements" + Model.UniqueId)
                          .HtmlAttributes(new { Class = "telerikGrid" })
                          .AutoBind(Model.GridAutoBind)
                          .Columns(columns =>
                              {
                                  columns.Bound(p => p.Prop1).HeaderTemplate("Header").Width(80);
                                  columns.Bound(p => p.Prop2).Width(280);
                                  columns.Bound(p => p.Prop3);
                              })
                          .Pageable(p => p.Messages(m => m.Display("{0} to {1} of {2}")))
                          .Sortable()
                          .Scrollable()
                          .Events(e => e.DataBound("gridNoDataMsgDisplay"))
                          .DataSource(dataSource => dataSource
                                                        .Ajax()
                                                        .Model(model => model.Id(p => p.EntityId))
                                                        .Sort(s => s.Add(t => t.Prop3).Descending())
                                                        .Read(read => read
                                                                          .Action("ApiControllerAction", "ApiController")
                                                                          .Type(HttpVerbs.Get).Data("grdEngagementsAjaxReadAdditionalFilterData" + Model.UniqueId))
                          ))

Controller

 //see telerik sample app Grid CustomAjaxBinding for details on how this works
        public JsonResult ApiControllerAction([ModelBinder(typeof(ModelBinders.DataSourceRequestModelBinder))] DataSourceRequest dataSourceRequest, string searchText, bool includeAll)
        {
            var request = dataSourceRequest.ToDataRequest();  // blows up at this point because dataSourceRequest is null
            var sortText = GetSortString(request.Sorts);
            return service.GetABC(request, searchText, sortText, includeAll)
                .ToKendoJsonResult<ABCServer, ABC>();
        }

2 Answers, 1 is accepted

Sort by
0
Accepted
Daniel
Telerik team
answered on 09 Aug 2013, 01:46 PM
Hello,

The code looks correct. Please verify that the ModelBinderAttribute and IModelBinder are from the correct assembly(should be System.Web.Http.ModelBinding). Also, verify that the kendo.aspnetmvc JavaScript file is correctly included.

Regards,
Daniel
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Manoj
Top achievements
Rank 1
answered on 12 Aug 2013, 08:59 AM
Thanks, reference to the dll was an issue and it's working now.
Tags
Grid
Asked by
Manoj
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Manoj
Top achievements
Rank 1
Share this question
or