【发布时间】:2015-09-16 09:45:06
【问题描述】:
我对 jquery-ui 很陌生。我想将this 与ajax 一起使用。 (ASP.NET MVC 5) 我创建了 jquery-ui-combobox.js 并在 jquery(combobox) 函数中添加。
我想这样使用。这个论点(来源)正确吗?
<script>
$(function () {
$("#combobox").combobox({source: function (request, response) {
$.ajax({
url: "/Home/GetProjects",
dataType: "json",
data: {
term: request.term
},
type: "POST",
success: function (data) {
/*I dont know what I should here*/
})
);
}
});});
$("#toggle").click(function () {
$("#combobox").toggle();
});
});
</script>
控制器:
public JsonResult GetProjects(string term)
{
var list = new List<SelectListItem>();
list.Add(new SelectListItem { Value = "1", Text = "ActionScript" });
list.Add(new SelectListItem { Value = "2", Text = "AppleScript" });
list.Add(new SelectListItem { Value = "3", Text = "Asp" });
var res = list.Where(p => p.Text.Contains(term));
return Json(res , JsonRequestBehavior.AllowGet);
}
Please help.
【问题讨论】:
标签: jquery ajax asp.net-mvc jquery-ui