Hi Cholet,
Thanks for using Syncfusion products.
You can set the input value to the autocomplete dataSource by converting the string data to the JSON object. Refer to the following code example:
[cs]
public JsonResult text(string data)
{
var userData = new UserData() { text = data };
UserData[] arr = new UserData[] { userData };
string json_data = JsonConvert.SerializeObject(arr);
return Json(json_data, JsonRequestBehavior.AllowGet);
} |
We have added the input value to the autocomplete dataSource by using the button click event.
Refer to the following code example:
[script]
function onclick() {
var data = $("#input").val();
$.ajax({
url: "/Home/text",
data: { data: data },
type: 'POST',
dataType: "json",
success: function (result) {
var data1 = JSON.parse(result);
var obj = $('#selectcar').data("ejAutocomplete");
obj.model.dataSource.push(data1[0]);
obj.option("dataSource", obj.model.dataSource);
obj.option("fields", { text: "text" });
}
});
} |
Refer to the following sample:
If you still face any difficulties, kindly get back to us. We will be happy to help you.
Regards,
Selvamani S.