Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 使用JSON自动完成_Jquery_Asp.net Mvc_Json - Fatal编程技术网

Jquery 使用JSON自动完成

Jquery 使用JSON自动完成,jquery,asp.net-mvc,json,Jquery,Asp.net Mvc,Json,在我看来,我有 @Html.TextBoxFor(per => per.Hospital, new { style = "width:220px", @maxlength = "50", data_autocomplete = Url.Action("HospitalList", "Person") }) 我的jquery是 $(document).ready(function () { $('input[data-autocomplete]'

在我看来,我有

@Html.TextBoxFor(per => per.Hospital, new { 
    style = "width:220px", @maxlength = "50", 
    data_autocomplete = Url.Action("HospitalList", "Person") })
我的jquery是

$(document).ready(function () {        
    $('input[data-autocomplete]').each(function () {
        var url = $(this).data('autocomplete');
        $(this).autocomplete({
            source: function (request, response) {
                $.getJSON(url, {
                    term: request.term
                }, response);
            }
        });
    });
});
我创造了一个新的行动结果

public ActionResult HospitalList(string term)
{
    List<string> result = new List<string>();
    result.Add("Hospital 1");
    result.Add("NYUMC");
    result.Add("Christ");
    result.Add("Bellevue");
    result.Add("NewYork-Presbyterian");
    result.Add("North Central Bronx Hospital");   

    result = result.Where(r => r.Contains(term)).ToList();         

    return Json(result , JsonRequestBehavior.AllowGet);
}  
public ActionResult医院列表(字符串术语)
{
列表结果=新列表();
结果。添加(“医院1”);
结果。添加(“纽约市城市轨道交通委员会”);
结果。添加(“基督”);
结果。添加(“Bellevue”);
结果。添加(“纽约长老会”);
结果:增加(“布朗克斯中北医院”);
result=result.Where(r=>r.Contains(term)).ToList();
返回Json(结果,JsonRequestBehavior.AllowGet);
}  
我包括了一个jquery库

<script src='<%: Url.Content("~/Scripts/jQueryUI/jquery-1.4.2.min.js") %>'    type="text/javascript"></script>  
<script src='<%: Url.Content("~/Scripts/jQueryUI/jquery-ui-1.8.2.custom.min.js") %>'  type="text/javascript"></script>


现在我错在哪里了。我看到的只是一个文本框,没有自动完成的行为

jQuery UI团队甚至在UI的1.8.6版之前都没有添加对jQuery 1.4.3的支持(请参阅)。因此,尽管可能存在其他问题,但也存在潜在的库不兼容问题

升级这两个库的版本,看看它首先会把你带到哪里


我希望这有帮助。

有JS控制台错误吗?jquery和jquery ui是否正在加载(jquery文件
“~/Scripts/jQueryUI/jquery-1.4.2.min.js”
上的路径吸引了我的眼球,但这并不意味着它是错误的;)没有错误。例如,如果我输入“h”。什么也没发生。我在ActionResult HospitalList(字符串项)方法中添加了一个断点。查询被执行,jason返回2个结果,但是我在ui中看到的是h,在我的文本框中没有对2个结果的建议ui的css在哪里?我认为您缺少jQueryUII的样式表。我没有用于ui的css。我想你是对的,我应该把什么css加上css工作谢谢穆罕默德。你是最好的。我从早上开始就在上面。。。。。。。。。。。