[英]Jquery autocomplete suggestion is not showing under textbox and showing at the bottom of the page in ASP.NET MVC
I have a textbox in ASP.Net MVC application at top of my Home page. 我的主页顶部的ASP.Net MVC应用程序中有一个文本框。
@Html.TextBox("place", Model.place,Model.place, new {id="place", @class = "form-control", @placeholder = "Search by Location" })
I am using Jquery to get suggestions: 我正在使用Jquery获得建议:
$(document).ready(function () {
$("#place").autocomplete({
source: function (request, response) {
$.ajax({
url: "/Search/AutoCompleteSearch",
type: "POST",
dataType: "json",
data: { term: request.term },
success: function (data) {
response($.map(data, function (item) {
return { label: item.SearchTerm, value: item.SearchTerm };
}))
}
})
},
messages: {
noResults: "", results: ""
}
});
})
In my controller i have written the following code: 在我的控制器中,我编写了以下代码:
public JsonResult AutoCompleteSearch(string term)
{
var searchResults = frequentsearchtermService.GetTerms(term);
return Json(searchResults, JsonRequestBehavior.AllowGet);
}
While executing my application it is showing suggestions, but instead of just below the text box, it shows after the footer of my page. 在执行我的应用程序时,它显示的是建议,而不是在文本框下方,而是显示在页面的页脚之后。
for proper working of the above code, need to give reference to the following script and css files: 为了使上述代码正常工作,需要参考以下脚本和CSS文件:
<link href="~/Content/css/jquery-ui.css" rel="stylesheet" />
<script src="~/Content/js/jquery-1.10.2.js"></script>
<script src="~/Content/js/jquery-ui.js"></script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.