背景:
我正在尝试将单个字符串发送到驻留在同一MVC应用程序中的Webapi。我正在使用Kendo数据源。
问题:
我的数据源调用正在联系我的Web api中的控制器函数,但是参数是以null为单位。
采取了各种JavaScript方法:
var clientLookupDataSource = new kendo.data.DataSource({
serverFiltering: true,
transport: {
read: {
type: "POST",
url: siteRoot + "api/GetClientInfo",
dataType: "json",
contentType: "application/json; charset=utf-8",
data: function (data) {
return JSON.stringify({ name: "Hello World"});
},
}
}
});
var clientLookupDataSource = new kendo.data.DataSource({
serverFiltering: true,
transport: {
read: {
type: "POST",
url: siteRoot + "api/GetClientInfo",
dataType: "json",
contentType: "application/json; charset=utf-8",
data: function (data) {
return JSON.stringify("Hello World");
},
}
}
});
var clientLookupDataSource = new kendo.data.DataSource({
serverFiltering: true,
transport: {
read: {
type: "POST",
url: siteRoot + "api/GetClientInfo",
dataType: "json",
contentType: "application/json; charset=utf-8",
data: function (data) {
return "Hello World";
},
}
}
});
C#WebApi 2.0控制器
[HttpPost]
[Route("api/GetClientInfo")]
public IHttpActionResult SearchClients([FromBody]string name)
{
return Ok("Response to" + name);
}
剑道自动完成
$("#clientddl").kendoAutoComplete({
dataSource: clientLookupDataSource,
placeholder: "Type client name...",
filter: "contains",
dataTextField: "ClientName",
dataValueField: "ClientRef",
enabled: true,
minLength: 3,
delay: 350,
change: function (e) {
var item = this.dataItem(e.item);
if (item != null) {
JobData.ClientId = item.ClientID;
doClientChange(e);
}
}
});