我正在尝试在我的文本框
上集成自动完成
。但它并没有调用 action
方法来从模型中获取数据。它在控制台中抛出以下错误:
http://localhost:56393/Api/AutoCompleteChannelName 404 (Not Found)
下面是 .cshtml 代码:
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
JavaScript:
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
$(document).ready(function () {
$("#channelName").autocomplete({
source: function (request, response) {
$.ajax({
url: "/Api/AutoCompleteChannelName",
type: "POST",
dataType: "json",
data: { term: request.term },
success: function (data) {
response($.map(data, function (item) {
return {
label: item.ChannelName,
};
}))
}
})
},
select: function (event, ui) {
event.preventDefault();
$("#channelName").val(ui.item.label);
$("#hdnChannelName").val(ui.item.label);
},
messages: {
noResults: "", results: ""
}
});
输入标签:
<input id="channelName" class="form-control" value="" name="channelName" placeholder="Enter Channel Name To Filter" />
操作结果:
public JsonResult AutoCompleteChannelName(string term)
{
List<DIM_CHANNEL> obj = bc.DIM_CHANNEL.Where(m => m.CHANNEL_NAME.ToLower().Contains(term.ToLower())).Distinct().AsEnumerable().Select(i => new DIM_CHANNEL
{
ChannelName = i.CHANNEL_NAME,
ChannelKey = i.CHANNEL_KEY,
}).ToList();
return Json(obj, JsonRequestBehavior.AllowGet);
}
任何帮助将不胜感激。
最佳答案
首先,将POST
更改为GET
。另外,您的 WebApiConfig.cs
中是否定义了 WebAPI 路由?
如果是这样,您需要删除该路由,或者将您的 Controller 重命名为 APIController
关于jquery - 文本框自动完成返回 404 错误,未找到 Controller /操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36864375/