C# 从kenod下拉列表将内容类型发送到webapi
我需要将contentType作为“application/json”发送到webApi控制器。下面是我使用的代码,它不起作用C# 从kenod下拉列表将内容类型发送到webapi,c#,jquery,asp.net-mvc-4,kendo-ui,kendo-asp.net-mvc,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!impo
@(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"));
})
)
您可以使用下面的KendoUIJQyery下拉列表来绑定JSON数据,而不是
@Html
帮助类,如下所示
HTML
<input id="ddlPatientClass" name="ddlPatientClass" class="custom-select" style="width: 100%;" />
你的控制器看起来怎么样我的问题是我如何使用剑道下拉列表将contenttype值发送给Api控制器方法。就像在ajax中一样,我们使用contentType:“application/json”的方式与我需要将contentType传递给api的方式相同
$(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 % --",
});
});