我在页面上有三个自动完成文本框,我无法弄清楚为什么其中一个没有获取源数据,该函数永远不会被触发但其他两个是。
这是我的JS:
$("#txtUserId").autocomplete({
delay: 0,
minLength: 0,
autoFocus: true,
source: function (request, response) {
$.ajax({
type: 'GET',
data: { 'data': request.term },
dataType: 'json',
url: '@Url.Action("GetAllUsers")',
success: function (data) {
response($.map(data, function (obj) {
return {
value: obj.Value,
label: obj.Text
}
}));
}
});
},
select: function (event, ui) {
neworold = "old";
$.ajax({
type: 'GET',
dataType: 'json',
url: '@Url.Action("GetUser")',
data: { userid: ui.item.value },
success: function (data) {
if (data.UserId == null) {
$("#lblError").text("User was not found");
$("#MessageDialog").dialog({ title: "User Maintenance" });
$("#MessageDialog").dialog("open");
}
else {
$("#txtUserName").val(data.UserName);
$("#txtUserRole").val(data.UserRole);
$("#chkUserAdmin").prop("checked", data.Admin);
$("#chkUserTrans").prop("checked", data.Trans);
$("#chkUserReports").prop("checked", data.Reports);
$("#txtUserId").val(data.UserId);
$("#txtFirstName").val(data.FirstName);
$("#txtLastName").val(data.LastName);
$("#txtInventoryRole").val(data.InventoryRole);
$("#txtDept").val(data.Department);
$("#lblRoleDesc").text(data.UserRoleDescription);
$("#lblInvRoleDesc").text(data.RoleDescription);
}
},
error: function (xhr) {
var err = xhr.responseText;
alert('error');
}
});
}
}).focus(function () {
$("#txtUserId").autocomplete('search', $("#txtUserId").val());
})
HTML:
<td>
<b style="color:red">*</b>Find User ID or Enter New:<br />
@Html.ValidationMessageFor(x=>x.UserId)
</td>
<td>
@Html.TextBoxForWithTitle(x=>x.UserId, new { @id = "txtUserId", style = "text-transform:uppercase", @class = "userModel, textboxsize"})
</td>
无论我在哪里移动它,它都不会启动源功能。我的行动:
[HttpGet]
public ActionResult GetAllUsers(string data)
{
List<TextValuePair> items = GetAllUsers();
var result1 = items.Where(item => item.toUpper().Contains(data.ToUpper())).ToList();
return Json(result1, JsonRequestBehavior.AllowGet);
}
有什么想法吗?非常令人费解的是,这是在上周工作,现在不是。不幸的是,我没有代码库,所以我无法获得早期版本。