0

私の見解では、私は持っています

@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);
}  

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>

今、私はどこが間違っていますか。テキストボックスが表示されるだけで、オートコンプリートの動作はありません。

4

1 に答える 1

2

jQuery UI チームは、UI のバージョン 1.8.6 まで jQuery 1.4.3 のサポートを追加しませんでした (こちらを参照)。したがって、他の問題が発生している可能性がありますが、ライブラリの非互換性もある可能性があります。

両方のライブラリのバージョンをアップグレードして、最初にどこに行くかを確認してください。

http://jquery.com/download/ http://jqueryui.com/download/ または https://developers.google.com/speed/libraries/devguide#jquery

これが役立つことを願っています。

于 2013-04-05T20:18:43.373 に答える