【发布时间】:2021-02-10 16:44:12
【问题描述】:
我的 Razor 项目的自动完成有一些问题。每次它返回我错误/失败。也许这甚至可能是一件愚蠢的事情,但我是 ASP 的新手,所以我很难注意到。 Javascript代码
$(function () {
$('#searchCliente').autocomplete({
source: function (request, response) {
$.ajax({
url: '/Index?handler=Search',
data: { "term": request.term },
type: "POST",
success: function (data) {
response($.map(data, function (item) {
return item;
}))
},
error: function (response) {
alert(response.responseText);
},
failure: function (response) {
alert(response.responseText);
}
});
},
select: function (e, i) {
$("#idCliente").val(i.item.val);
$("#idFatt").val(i.item.val);
},
minLength: 3
});
});
页面模型代码
public IActionResult OnPostSearch(string term)
{
var clientefatt = (from cliente in this.context.Arc_Anagrafiche
where cliente.RagioneSociale.StartsWith(term)
select new
{
label = cliente.RagioneSociale,
val = cliente.IdAnag
}).ToList();
return new JsonResult(clientefatt);
}
HTML 代码
<input asp-for="intervento.Cliente" class="form-control" id="searchCliente" />
<input asp-for="intervento.IdClienteFatturazione" class="form-control" id="idCliente" type="hidden" />
【问题讨论】:
-
请查看我的回复,问题是否与AddAntiforgery有关,是否解决了问题?如果问题仍然存在,请尝试使用 F12 开发者工具检查是否有 JavaScript 错误?如果它解决了问题,我建议您在可以标记时尝试将其标记为该问题的已接受答案。它可以在未来帮助其他社区成员解决类似的问题。感谢您的理解。
-
我会尽快检查,因为这周我已经搁置了项目的这一部分。
标签: javascript jquery asp.net-core asp.net-ajax razor-pages