أماني مفيد

أماني مفيد

  • NA
  • 142
  • 17.3k

Autocomplete Text box MVC

Aug 30 2020 6:33 AM
i have a autocomplete text box 
 
this is the controller  
[HttpPost]
public ActionResult GetRecord(string prefix)
{
DataSet dst = new DataSet();
dst.Tables.Add(op.GetName(prefix));
List<DataSearch> searchlist = new List<DataSearch>();
foreach (DataRow dr in dst.Tables[0].Rows)
{
searchlist.Add(new DataSearch
{
label = dr["ARTICAL_NAME"].ToString(),
val = dr["ARTICL_ID"].ToString()
});
}
return Json(searchlist);
}
 
and this is the Ajax 
$(document).ready(function () {
SearchText();
});
function SearchText() {
$("#MyId").autocomplete({
source: function (request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: '/Home/GetRecord',
data: "{'prefix':'" + document.getElementById('MyId').value + "'}",
dataType: "json",
success: function (json) {
//alert( json[0].label);
response(json)
{
//alert( json[0].label);
$("#MyId").append($("<option></option>").val(json[0].label).html(json[0].label)); }
},
error: function (result) {
alert("No Match");
}
});
}
});
}
</script>
i want resutl appaer as drop down list 
 
any help ?  
 

Answers (4)