Sneha K

Sneha K

  • 1.2k
  • 527
  • 195.6k

Autocomplete Dropdown is not working in mvc4?

Mar 14 2016 12:54 AM
Hi I have one field called CustomerName it is Dropdown. I want to make this field as Auotcomplete dropdown instead of selecting the value . but i cant get any idea to do this task . im 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 
 
<script>
$(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. Please any one help me to do that Autocomplete dropdown task. I tried manys but no use no one is working..
 
 
Advance Thanks.. 
 
 
 
 

Answers (5)