简体   繁体   English

jQuery自动完成建议未显示在文本框下方,也不显示在ASP.NET MVC页面底部

[英]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.

相关问题 使用Ajax和jQuery的ASP.NET MVC4中的自动完成文本框 - Autocomplete textbox in asp.net mvc4 using ajax and jQuery 自动完成功能未在我的asp.net MVC中显示任何CSS - Autocomplete is not showing any CSS inside my asp.net mvc 与asp.net MVC Fullcalendar不显示事件 - Fullcalendar with asp.net mvc not showing events jQuery自动完成-TypeError:自动完成不是ASP.NET MVC 5中的函数 - jQuery autocomplete - TypeError: autocomplete is not a function in asp.net mvc 5 jQuery自动完成功能不会在ASP.NET中调用文本框 - jQuery Autocomplete Doesn't Invoke For Textbox in ASP.NET 如何使用jquery在asp.net中为文本框自动完成 - How to do autocomplete for textbox in asp.net using jquery 页面中包含的脚本中带有url.action助手的ASP.NET MVC jQuery自动完成功能 - ASP.NET MVC jQuery autocomplete with url.action helper in a script included in a page 如何停止在页面加载时显示部分视图 - ASP.NET MVC - How can I stop showing a partial view on page load - ASP.NET MVC 从数据库加载时网页挂起,大数据未显示在asp.net mvc5的图表上 - web page is hanging while loading from DB and large data not showing on charts in asp.net mvc5 Asp.Net MVC 5 jQuery验证不适用于带有提交事件的Ajax帖子,显示为有效表单 - Asp.Net MVC 5 Jquery validation not working on ajax post with submit event, showing as valid form
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM