I have an autocomplete text field, that uses JSON like so:
$(function () {
var src = \'@Url.Action(\"GetParts\", \"Parts\")\'
You can do that in the select
event of the autocomplete.
$(function () {
var src = '@Url.Action("GetParts", "Parts")'
$("#autoCompleteBox").autocomplete({
source: function (request, response) {
$.ajax({
url: src,
async: true,
dataType: "json",
data: {
partNumber: $("#autoCompleteBox").val()
},
success: function (data) {
response(data[0]);
}
});
},
select: function (event, ui) {
var item= ui.item.label;
//Now make the ajax call here
$.post("SomeValidUrl", new { id : item } ,function(res){
// do something with res
});
}
});
});