简体   繁体   English

自动完成的jQuery插件不起作用ASP.Net MVC 4

[英]Autocomplete jquery Plugin not working ASP.Net MVC 4

-Hello Guys , I am trying to use autocomplete in jquery, this is my code : -Hello Guys,我正在尝试在jquery中使用自动完成功能,这是我的代码:

-This action is placed on a controller named Agence in an area called Admin. -此操作放置在名为Admin的区域中名为Agence的控制器上。

public JsonResult GetAgences(string term)
        {
            return Json(_agenceRepo.SearchByNom(term), JsonRequestBehavior.AllowGet);
        }

-Here is the method of the repository that returns the Value to JSon : -这是将Value返回到JSon的存储库方法:

public IList<Agence> SearchByNom(string nom)
        {
            return _context.Agences.Where(a => a.Nom.Contains(nom)).ToArray();
        }

-This is the jquery code : -这是jQuery代码:

<label for="completeMe">Find:</label>
<input type="text" id="completeMe" />
<script type="text/javascript">
    $(function () {
        $("#completeMe").autocomplete({
            source: '@Url.Action("GetAgences", "Agence")',
            minLength: 1
            }
        });
    });
</script>

-All of this code is placed in one page, the one that has the searching field. -所有这些代码都放在一个页面中,该页面具有搜索字段。 -Here is my JQuery references on the master page : -这是我在主页上的JQuery参考:

<meta charset="utf-8" />
    <title>@ViewBag.Title - My ASP.NET MVC Application</title>
    <link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
    @Styles.Render("~/Content/css")
    <link href="@Url.Content("~/Content/themes/base/Bootstrap/bootstrap.css")" rel="stylesheet" type="text/css" />
    @Scripts.Render("~/bundles/modernizr")
    @Scripts.Render("~/bundles/jquery")
    <script src=  "@Url.Content("~/Scripts/Bootstrap/bootstrap.min.js")" type="text/javascript"></script>

-I followed all the needed steps but nothing happens when I want results of search. -我遵循了所有必需的步骤,但是当我想要搜索结果时什么也没有发生。 I suspect that the problem is in my jQuery references. 我怀疑问题出在我的jQuery参考中。 Thank You. 谢谢。

I think there is issue with your ajax call, you have not specified the param. 我认为您的ajax调用存在问题,您尚未指定参数。 Do like this: 这样做:

<script type="text/javascript">
$(function () {
    $("#completeMe").autocomplete({
        source: '@Url.Action("GetAgences", "Agence")',
        data: {term: 'xyz'}
        minLength: 1
        }
    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM