C# 设置自动完成文本框的值
在MVC框架中的应用 从员工列表中,当用户单击编辑按钮时,特定的员工数据将显示在页面中。我为用户添加了一个自动完成文本框 我想根据单击的员工数据设置自动完成值C# 设置自动完成文本框的值,c#,jquery,model-view-controller,autocomplete,C#,Jquery,Model View Controller,Autocomplete,在MVC框架中的应用 从员工列表中,当用户单击编辑按钮时,特定的员工数据将显示在页面中。我为用户添加了一个自动完成文本框 我想根据单击的员工数据设置自动完成值 $("#autoAssginedTo").autocomplete({ source: function (request, response) { $.ajax({ url: "/LeadGeneration/GetUsers",
$("#autoAssginedTo").autocomplete({
source: function (request, response) {
$.ajax({
url: "/LeadGeneration/GetUsers",
type: "GET",
dataType: "json",
data: { Prefix: request.term },
success: function (data) {
response($.map(data, function (item) {
return { label: item.FirstName + ' ' + item.LastName, value: item.FirstName + ' ' + item.LastName, val: item.ID };
}))
}
})
},
messages: {
noResults: "", results: ""
},
select: function (e, i) {
$("#AssignedTo").val(i.item.val);
},
});
我尝试了以下几点:
function setAutocompletCurrentValue(id, value) {
$(id).val(value);
var textToShow = $(id).find(":selected").text();
$(id).parent().find("span").find("input").val(textToShow);
}
但它设置了用户的id。我想设置与empId关联的员工姓名
如何做到这一点?而不是:
$("#AssignedTo").val(i.item.val);
用这个替换它:
$("#AssignedTo").val(i.item.label);