Moti Mashiah
asked on
Asp.net mvc 5
hi Guys,
I have mvc application and I implemented autocomplete that return params with ajax:
see my code:
After I'm getting the value into the text box I would like to click on the GO button and send this value to the controller with ajax.
Here is my text:
Can somebody give me an idea how to do it.
I have mvc application and I implemented autocomplete that return params with ajax:
see my code:
$("#Search").autocomplete({
source: function (request, response) {
$.ajax({
url: "/Categorymanager/Autocomplete",
type: "POST",
dataType: "json",
data: { Prefix: request.term },
success: function (data) {
response($.map(data, function (item) {
return {
label: item.Deptname + item.Categoryname,
Value: item.Value
};
}))
}
})
},
minChars: 2,
minLength: 2,
autoFill: true,
select: function (event, ui) {
$("#Search").val(ui.item.Value);
return false;
},
messages: {
noResults: "", results: ""
}
}).data("ui-autocomplete")._renderItem = function (ul, item) {
return $("<li></li>")
.data("item.autocomplete", item)
.append("<div><strong style='color:red;'>" + item.label + "</strong><strong style='color:blue;'>" + "|" + " " + item.Categoryname + "</strong></div>")
.appendTo(ul);
}
});
});
After I'm getting the value into the text box I would like to click on the GO button and send this value to the controller with ajax.
Here is my text:
Can somebody give me an idea how to do it.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
this is my server side code:
I can return more than one value to the property value, but I don't want to show more than one value in the textbox.
I hope you got my point.
THanks,
public JsonResult Autocomplete(string Prefix)
{
ALThompsonCRMEntities ald = new ALThompsonCRMEntities();
RMSmasterHQEntities db = new RMSmasterHQEntities();
var search = ald.CatManSearchAutocomplete(Prefix)
.Select(a => new Searchresult
{
Deptname = a.DeptName,
Categoryname = a.CategoryName,
Value = a.DeptName
}).ToList();
return Json(search, JsonRequestBehavior.AllowGet);
}
I can return more than one value to the property value, but I don't want to show more than one value in the textbox.
I hope you got my point.
THanks,
check this recent question : https://www.experts-exchange.com/questions/28688532/jquery-autocomplete.html?anchorAnswerId=40823782#a40823782
ASKER
thx
ASKER
I want to show in my textbox just one value but return 4 values to the method you just posted.
look at this code in my autocomplete method:
select: function (event, ui) {
$("#Search").val(ui.item.V
return false;
},