我需要将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"));
})
)
答案 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 % --",
});
});