【发布时间】:2017-06-27 09:36:17
【问题描述】:
我有一个剑道下拉列表。我正在对我的 web api 进行 ajax 调用以绑定它。 下拉列表:
@(Html.Kendo().DropDownList()
.Name("ddlDepartment")
.DataValueField("DeptId")
.DataTextField("DeptName")
.SelectedIndex(0)
.AutoBind(false)
)
对 Web Api 的 Ajax 调用:
$(document).ready(function () {
var ddl = $('#ddlDepartment').data("kendoDropDownList");
jQuery.support.cors = true;
$.ajax({
url: 'http://localhost:8648/api/dropdown/',
type: 'GET',
dataType: 'json',
success: function (data) {
debugger;
alert(data);
ddl.setDataSource(data);
},
error: function (x, y, z) {
alert(x + '\n' + y + '\n' + z);
}
});
})
但我想直接将它与 Api 绑定,就像我们在默认 mvc 控制器中使用普通操作方法绑定它一样。 我的 API 方法:
// GET api/dropdown
public IEnumerable<Department> Get()
{
List<Department> depart = _departmentTask.GetAll();
return depart;
}
【问题讨论】:
标签: jquery ajax asp.net-mvc asp.net-web-api