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 = "" })
)

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 eg

$(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")))
  ))
链接地址: http://www.djcxy.com/p/33712.html

上一篇: 如何为ONEPLUS TWO创建模拟器?

下一篇: 如何使用JSON作为contentType使Kendo MVC Helpers的CRUD