Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
am using autocomplete ajax function on text-box. till what i have done is. using ajax auto-complete function it will fetch all data from table columns.

Example :

In my columns U.S.A, Canada,London ,u.s.a,India,china,London,u.s.a, etc When i type on textbox as u.s.a. it fetch u.s.a,u.s.a,u.s.a,

Problem is,

i don't need to fetch repeated data when i type u.s.a

it should return u.s.a

not u.s.a,u.s.a,u.s.a,

Controller
public JsonResult GetLocation(string term)
        {
            SYTEntities db = new SYTEntities();
            List<string> Location = new List<string>();
            {
                Location.AddRange(db.tblAddresses.Where(x => x.City.StartsWith(term))
                       .Select(y => y.City).ToList());
                Location.AddRange(db.tblAddresses.Where(x => x.State.StartsWith(term))
                      .Select(y => y.State).ToList());
            }
            return Json(Location, JsonRequestBehavior.AllowGet);
        }

XML
View

<input type="search" name="txtLocation" id="txtLocation" value="@Session["location"]" placeholder=" City or State">

    <script type="text/javascript">
        $(document).ready(function () {
            $("#txtValue").autocomplete({
                source: '@Url.Action("Getbusiness")',
                minLength: 1
            });
            $("#txtLocation").autocomplete({
                source: '@Url.Action("GetLocation")',
                minLength: 1
            });
        });
    </script>
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900