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

How to use the DataSourceRequest as a parameter in a WebAPI GET method?

3 Answers 1665 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Oscar
Top achievements
Rank 1
Oscar asked on 26 Oct 2012, 09:04 PM
Hello,

After reading the MVC AJAX binding sample code:
http://docs.kendoui.com/getting-started/using-kendo-with/aspnet-mvc/helpers/grid/ajax-binding

I considered using the DataSourceRequestAttribute and DataSourceRequest in a WebAPI Get method. The signature would look like this:

public DataSourceResult Get([DataSourceRequestAttribute] DataSourceRequest request)

I configured the Grid to make the AJAX request as a Get. However it doesn't work. After some research I found out ModelBinders in WebAPI have to implement the System.Web.Http.ModelBinding.IModelBinder, while MVC requires implementing the System.Web.Mvc.IModelBinder interface instead.

Everything works fine, but that's not very REST-compliant. I rather call the Get method from the grid and pass all parameters in the query string.

This question is for Telerik: Do you have something in place (or planning to implement) similar to "ApiDataSourceRequestAttribute" that returns a ModelBinder based on System.Web.Http.ModelBinding.IModelBinder to bind the Get query string parameters to a DataSourceRequest?

Thanks.






3 Answers, 1 is accepted

Sort by
0
leblanc
Top achievements
Rank 1
answered on 08 Jan 2014, 06:13 AM
Just ran into the same problem - now that web api 2 is out was migrating from mvc to web api.

they have the modelbinder here: - http://www.kendoui.com/code-library/mvc/grid/binding-to-a-web-apicontroller.aspx

details here:

http://www.kendoui.com/blogs/teamblog/posts/12-11-29/the_facts_on_using_kendo_ui_with_asp_net_webapi.aspx#mvc-vs-webapi-parameter-binding



0
Mani
Top achievements
Rank 1
answered on 07 Aug 2015, 02:19 AM
I configured one of the solution but it shows "WebApiDataSourceRequestModelBinder" reference could not found...But i used Kendo.mvc reference..I don't know what to do next.Please give some suggestions
0
Rosen
Telerik team
answered on 12 Aug 2015, 06:31 AM

Hello Mani,

You should verify that you are using at least Q1 2014 version of UI for ASP.NET MVC and ASP.NET MVC 4 or 5. Information on how to bind Grid widget to WebApi controller can be found in this help article. Also a runnable sample is available in the sample application which is accompanying the UI for ASP.NET MVC distribution

Regards,
Rosen
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Data Source
Asked by
Oscar
Top achievements
Rank 1
Answers by
leblanc
Top achievements
Rank 1
Mani
Top achievements
Rank 1
Rosen
Telerik team
Share this question
or