TextBoxFor Autocomplete MVC [英] TextBoxFor Autocomplete MVC

查看:81
本文介绍了TextBoxFor Autocomplete MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我看来,我有



In my view i have

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





我的jquery是





My jquery is

$(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);
            }
        });
    });
});





创建一个新的动作结果





And a created a new Action result

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");            

        return Json(result , JsonRequestBehavior.AllowGet);
    }  



现在我去哪里wromg。我只看到一个文本框,没有自动完成的行为。我是否应该包含任何jquery库以使其工作


now where am i going wromg. All I see a a text box , no behavior of auto complete. Should i be including any jquery library for it to work

推荐答案

document )。ready( function (){
(document).ready(function () {


' input [data_autocomplete]')。each( function (){
var url =
('input[data_autocomplete]').each(function () { var url =


this )。data('' autocomplete');
(this).data('autocomplete');


这篇关于TextBoxFor Autocomplete MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆