当我使用 JQuery 的自动完成并对页面中的数组值进行硬编码时,它的效果非常好;但我需要做的是从 Web 服务或控制器内的公共函数中获取数组值。我尝试了各种方法,似乎无法使其工作。我得到的最远的是将数据拉入一个长字符串,当提供自动完成结果时,它是匹配的长字符串,我明白为什么。
$("#TaskEmailNotificationList").autocomplete("http://localhost/BetterTaskList/Accounts/registeredUsersEmailList", {
multiple: true,
mustMatch: false,
multipleSeparator: ";",
autoFill: true
});
有没有人遇到过这个?我正在使用 C#。
更新: 下面的代码是向前迈出的一步,我现在正在返回一个数组,但我认为我在我的页面上处理它错误。
var emailList = "http://localhost/BetterTaskList/Account/RegisteredUsersEmailList";
$("#TaskEmailNotificationList").autocomplete(emailList, {
multiple: true,
mustMatch: false,
multipleSeparator: ";",
autoFill: true
});
[HttpGet]
public ActionResult RegisteredUsersEmailList()
{
BetterTaskListDataContext db = new BetterTaskListDataContext();
var emailList = from u in db.Users select u.LoweredUserName;
return Json(emailList.ToList(), JsonRequestBehavior.AllowGet);
}