@(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 which initialized using HTML helper way instead of JQuery way.
Is there anyway to make the post request to /Service/GetServiceRepository using JSON
as contentType instead of the default application/x-www-form-urlencoded
?
This Kendo MVC Helper does not support setting the content type. It is designed to work with the MVC controllers and the Kendo MVC server API and so not all request options can be set. You should use the JavaScript initialization in order to be able to set all options. It is possible to modify the options via JavaScript after the helper has already been initialized e.g.
$(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);
}
});
You can set the ContentType property using DataSource's Custom fluent method. I use version 2016.2.504.
The usage is:
@(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")))
))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With