How to force Kendo MVC Helpers CRUD to use JSON as contentType

@(Html.Kendo().DropDownListFor(model => model.ServiceID) .OptionLabelTemplate("#=optionLabel#") .ValueTemplate("#=Code#(#=Rate#) - #=Description#") .Template("#=Code#(#=Rate#) - #=Description#") .DataTextField("Code") .DataValueField("ServiceID") .DataSource(d => { d.Read(read => { read.Action("GetServiceRepository", "Service").Data("...") .Type(HttpVerbs.Post); }); }) .OptionLabel(new { optionLabel = Resources.Wording.SelectOne, ServiceID = 0, Rate = 0, Code = "" }) ) 

I have a Kendo Dropdownlist that is initialized using an HTML helper instead of jQuery.

In any case, to make a request to send / Service / GetServiceRepository using JSON as contentType instead of the standard application/x-www-form-urlencoded ?

+7
json javascript jquery asp.net-mvc kendo-asp.net-mvc
source share
2 answers

This Kendo MVC helper does not support content type customization. It is designed to work with MVC controllers and the Kendo MVC API, so not all request parameters can be set. You must use JavaScript initialization to be able to set all parameters. You can change the parameters via JavaScript after the helper is already initialized, for example.

 $(function () { var grid = $("#grid").data("kendoGrid"); grid.dataSource.transport.options.update.contentType = "application/json"; //override the parameterMap function in order to convert the data to JSON grid.dataSource.transport.parameterMap = function (options, type) { return kendo.stringify(options); } }); 
+2
source share

You can set the ContentType property using the Custom DataSource method. I am using version 2016.2.504.

Using:

  @(Html.Kendo().DropDownListFor(model => model.ServiceID) .DataTextField("Text") .DataValueField("Value") .DataSource(d => d.Custom() .Transport(c => c.Read( read => read.ContentType("xml/json") .Data("...") .Type(HttpVerbs.Post) .Action("GetServiceRepository", "Service"))) )) 
+1
source share

All Articles