i have auto complete text box
this is the script
- "stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
- 'CountryName'/>
- 'CountryID'>
- var data2;
- $.ajax({
- url: '/Home/GetRecord',
- dataType: "json",
- data: data2,
- success: function (data) {
- data2 = data;
- },
- error: function (xhr, status, error) {
- alert("Error");
- }
- });
- $('#CountryName').autocomplete({
- data: { search: $("#searchInput").val() },
- source: function y(request, response) {
- response($.map(data2, function (item) {
- return {
- label: item.t,
- value: item.t
- }
- }));
- }
- ,
- select: function (e, ui) {
- e.preventDefault();
- $(this).val(ui.item.label);
- $('#CountryID').html(ui.item.value);
- }
- });
this is the controller
- [HttpGet]
- public JsonResult GetRecord(string prefix)
- {
- DataSet dst = new DataSet();
- dst.Tables.Add(op.GetName(prefix));
- List
searchlist = new List (); - foreach (DataRow dr in dst.Tables[0].Rows)
- {
- searchlist.Add(new DataSearch
- {
- t = dr["ARTICAL_NAME"].ToString()
- });
- }
- return Json(searchlist , JsonRequestBehavior.AllowGet);
- }
when i click in text box that ajax call not work , i call it from url like this https://localhost:44330/home/GetRecord?prefix=t
and the result
[{"t":"test"},{"t":"test from it "},{"t":"table "}] and appear in new page
any help to make result appear as dropdown when i start write inside textbox
Nisha RegilPosted Sep 3, 2020, 5:51 AM
Farhan AhmedPosted Sep 3, 2020, 2:09 AM