2
votes

To send kendo datasource request to webapi, I have serilized the kendo dataSourcerequest to string to apply filter and sorting operations in webapi. But when deseralizing the string to dataSourcerequest i am getting error as "token expected"

Controller :

public ActionResult GetGridData([DataSourceRequest] DataSourceRequest request)
{
      //converting object to string
      string jsonStr = JsonConvert.SerializeObject(request);
}

Web api:

public ActionResult GetGridData(string request)
   {
        //converting string into object
        string jsonStr = JsonConvert.DeSerializeObject<DataSourceRequest>(request);
        //Here error is throwing as "Expected Token"
    }

DataSourceRequest: { Page : 1, PageSize : 10, Sorts : [], filters : { [{ "value":"Accident Response Fee Laws","operator":"eq","field":"subTopic"}],"logic":"or"} }

2
Can you post the contents of the request string and the structure of your DataSourceRequest.Thangadurai
@Thangadurai Please check the updated answerArjun
post your DataSourceRequest class also.Thangadurai
Your JSON content looks invalid. There is an extra } at the end.Thangadurai
That was just copy paste error, DataSourceRequet is kendo classArjun

2 Answers

1
votes

Currently Telerik does not support serialising the DataSourceRequest. This class implements interfaces inside of the class, preventing the class from being serialised.

The best way I can think of handling this is to create a custom class that will convert the DataSourceRequest to a custom serialisabe class. This would also require you to include a function to convert the custom class back to the DataSourceRequest Telerik class.

There is a current request for this feature. Please vote here to try and get Telerik to implement this functionality: http://kendoui-feedback.telerik.com/forums/127393-kendo-ui-feedback/suggestions/17207828-serialization-support-of-datasourcerequest-and-app

0
votes

Just pass over the data as a query string

in your angular

const queryStr = `${toDataSourceRequestString(gridState)}`;
 return this._http
      .post(`${url}?${queryStr}`)

in your webapi

using Kendo.Mvc.UI;
using System.Web.Http.ModelBinding;
public ActionResult GetGridData([ModelBinder(typeof(WebApiDataSourceRequestModelBinder))] DataSourceRequest request)
   {
   }