将内容类型从kenod下拉列表发送到webapi

时间:2017-04-10 11:59:54

标签: c# jquery asp.net-mvc-4 kendo-ui kendo-asp.net-mvc

我需要将contentType作为“application / json”发送到webApi控制器。下面是我使用的代码,它不起作用。

 @(Html.Kendo().DropDownList()
                                  .Name("ddlPatientClass").AutoBind(true)
                                  .HtmlAttributes(new { style = "width: 67px!important;" })
                                  .DataTextField("ModuleName")
                                  .DataValueField("RoleId")   
                                  .ContentType("application/json")        
                                  .DataSource(source =>
                                  {
                                      source.Read(read => read.Url(Url.HttpRouteUrl("DefaultApi", new { controller = "MedicalVisit", Action = "GetPatientClass" })).Type(HttpVerbs.Get));//.Type(HttpVerbs.Get).Data("ModuleParamCP"));
                                  })
                                )

1 个答案:

答案 0 :(得分:0)

您可以使用以下Kendo UI JQyery下拉列表来绑定JSON数据,而不是@Html帮助程序类。

<强> HTML

<input id="ddlPatientClass" name="ddlPatientClass" class="custom-select" style="width: 100%;" />

<强> JQuery的

$(document).ready(function () {

    var data = [
        { text: "0", value: "0" },
        { text: "10", value: "10" },
        { text: "25", value: "25" },
        { text: "30", value: "30" },
        { text: "100", value: "100" }
    ];
    // This data you can get from WebApi - using Ajax call

    // After get JSON data from webApi - you can create DropDownList as below


    $("#ddlPatientClass").kendoDropDownList({
        dataTextField: "text",
        dataValueField: "value",
        dataSource: data,
        index: 0,
        optionLabel: "-- Choose % --",
    });
});