如何使用 JSON 作为 contentType 制作 Kendo MVC Helpers 的 CRUD
How to make Kendo MVC Helpers's CRUD using 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 = "" })
)
我有一个 Kendo 下拉列表,它使用 HTML 辅助方式而不是 JQuery 方式进行初始化。
是否可以使用 JSON
作为 contentType 而不是默认的 application/x-www-form-urlencoded
向 /Service/GetServiceRepository 发出 post 请求?
您可以使用 DataSource 的 Custom 流畅方法设置 ContentType 属性。我用的是2016.2.504版本。
用法是:
@(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")))
))
此Kendo MVC Helper 不支持设置内容类型。它旨在与 MVC 控制器和 Kendo MVC 服务器 API 一起使用,因此并非所有请求选项都可以设置。您应该使用 JavaScript 初始化以便能够设置所有选项。在 helper 已经初始化后,可以通过 JavaScript 修改选项,例如
$(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);
}
});
@(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 = "" })
)
我有一个 Kendo 下拉列表,它使用 HTML 辅助方式而不是 JQuery 方式进行初始化。
是否可以使用 JSON
作为 contentType 而不是默认的 application/x-www-form-urlencoded
向 /Service/GetServiceRepository 发出 post 请求?
您可以使用 DataSource 的 Custom 流畅方法设置 ContentType 属性。我用的是2016.2.504版本。
用法是:
@(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")))
))
此Kendo MVC Helper 不支持设置内容类型。它旨在与 MVC 控制器和 Kendo MVC 服务器 API 一起使用,因此并非所有请求选项都可以设置。您应该使用 JavaScript 初始化以便能够设置所有选项。在 helper 已经初始化后,可以通过 JavaScript 修改选项,例如
$(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);
}
});