i am using Auto complete text box in MVC. Here the data is bind to textbox when i entered any key in textbox its populating database values. the problem is i want how to get id's and bind to one hiddenfied.
thanks in advance.
syam k
What I have tried:
In controller:
public JsonResult Langs(string Prefix)
{
CRA_DBEntities dbname = new CRA_DBEntities();
var dbnames = new object();
//List<string> dbnames;
var dbnameswithid = new object();
dbnameswithid = dbname.ConstantDatabaseTypes.Where(x => x.DatabaseName.Contains(Prefix)).Select(y => new { id = y.ConstDatabaseTypeID, label = y.DatabaseName }).ToList();
//dbnames = dbname.ConstantDatabaseTypes.Where(x => x.DatabaseName.Contains(Prefix)).Select(y => y.DatabaseName).ToList();
//dbnames = dbname.ConstantDatabaseTypes.Where(x => x.DatabaseName.Contains(term)).Select(y => new { y.ConstDatabaseTypeID, y.DatabaseName }).ToList();
//ViewData["dbnamewithid"] = dbnameswithid;
return Json(dbnameswithid, JsonRequestBehavior.AllowGet);
}
In my JS is:
$(function () {
debugger;
var ter=$("#dbComplete").val
$('#dbComplete').autocomplete({
source: function (request, response) {
$.ajax({
url: '@Url.Action("Langs")',
type: "POST",
datatype: "json",
data: { Prefix: request.term },
success:function(data)
{
response($.map(data, function (item) {
alert(item.Name)
}));
},
error:alert('error')
});
}
});
});