weixin_33743248 2016-03-14 05:34 采纳率: 0%
浏览 21

在mvc4中自动完成下拉列表?

Hi I have one field called CustomerName it is drop down. I want to make this field as Autocomplete drop down instead of selecting the value . But i can't get any idea to do this task . i am getting lot of confusions so please any one help me to solve this issue

My Controller code

public JsonResult GetCustomers()
{
    return Json(db.Customers.ToList(), JsonRequestBehavior.AllowGet);
}

My View Code

@Html.Label("Customer Name", new { @class = "control-label" })
@Html.DropDownListFor(model => model.CustomerID, new SelectList(string.Empty, "Value", "Text"), "Please select a Customer", new { @class = "form-control required", type = "text" })

My J-query Code

$(function () {
    $.ajax(
        '@Url.Action("GetCustomers", "VisitorsForm")',{
         type: "GET",
         datatype: "Json",
         success: function (data) {
             $.each(data, function (index, value) {
                 $('#CustomerID').append('<option value="' + value.CustomerID + '">' + value.DisplayName + '</option>');
             });
         }
    });
});

This is my code it will load the CustomerName in CustomerName Field from Db.it is perfectly working . But i want to make this field as Autocomplete Dropdown.I tried many ways but no use no one is working for this task. Please any one help me to complete this Autocomplete dropdown task.

Advance Thanks..

  • 写回答

1条回答 默认 最新

  • weixin_33739541 2016-03-14 06:16
    关注

    why are you giving type = "text" for a dropdown. Actually you need to use jquery-autocomplete . Follow the tutorial:http://www.tutorialspoint.com/jqueryui/jqueryui_autocomplete.htm

    评论

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b