@model InventoryManagement.Models.ViewModel.AddBom
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@{
}
<div class="bg-secondary bg-opacity-10 py-2">
<div class="container">
<h1>
Add BOM
</h1>
</div>
</div>
<div class="container py-5">
<form method="post">
<div class="mb-3">
<label class="form-label">Item Name</label>
<input type="text" class="form-control" id="itemname" asp-for="Itemlist" />
</div>
</form>
</div>
@section Scripts
{
<script type="text/javascript" src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.10.0.min.js"></script>
<script type="text/javascript" src="https://ajax.aspnetcdn.com/ajax/jquery.ui/1.9.2/jquery-ui.min.js"></script>
<link rel="Stylesheet" type="text/css" href="https://ajax.aspnetcdn.com/ajax/jquery.ui/1.9.2/themes/blitzer/jquery-ui.css" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" />
<script type="text/javascript">
$(document).ready(function () {
var kk = function (request, response) {
$.ajax({
url: '/Bom/AutoComplete/',
data: { "prefix": request.term },
type: "POST",
success: function (data) {
var formattedData = $.map(data, function (item) {
return {
label: item.label,
value: item.val
};
});
response(formattedData);
console.log("888", formattedData)
},
error: function (response) {
alert(response.responseText);
},
failure: function (response) {
alert(response.responseText);
}
});
};
console.log("888hh", kk);
$("#itemname").autocomplete({
source: function (request, response) {
kk(request, response);
alert("llllllllllllllllllllll");
},
select: function (e, i) {
//get selected value
//$("#personNameValue").val(i.item.val);
},
});
});
</script>
}
This is the Add.cshtml file. Here the success function is working and console.log is outputting value, but the value is not displaying in dropdown.
This is the Bomcontroller.cs and is correctly fetching values:
[HttpPost("AutoComplete")]
public JsonResult AutoComplete(string prefix)
{
var persons = (from item in this.jobdbcontext.ItemMaster
where item.itemname.StartsWith(prefix)
select new
{
label = item.itemname,
val = item.itemid
}).Take(5).ToList();
return Json(persons);
}

F12to see if any error message ? "but the value is not displaying in dropdown." What's your dropdown ?