Click here to Skip to main content
15,911,789 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can i add mvc3 Autocomplete textbox changed event same as cascading dropdownlist. Below is my code in this code i want after entering statesText data automatically cities text will be changed.

my view code.
<div style="float: left">
States Filter :
</div>
<div style="float: left; padding-removed 10px">
@Html.TextBox("Statestxt")
@Html.TextBox("Citiestxt")
</div>
<div style="padding-removed 10px; float: left">
<input type="image" value="submit" src="../../Images/FilterBrowse.gif" 
alt="submit Button" /> 
</div>
 <script type="text/javascript">
        $(document).ready(function () {
            $("#Statestxt").autocomplete({
                source: '@Url.Action("AutocompleteAsync")'});
                $("#Citiestxt").autocomplete({
                source: '@Url.Action("AutocompleteCity")'
            });
        });
    </script>

**My controller:**
[NoCache]
public ActionResult AutocompleteAsync(string term)
{ 
var suggestions = from s in Adm.states
select s.state_name;
var namelist = suggestions.Where(n => n.ToLower().StartsWith(term.ToLower()));
return Json(namelist, JsonRequestBehavior.AllowGet);
}

[NoCache]
        public ActionResult AutocompleteCity(string term)
        {
            var suggestions = from s in Adm.cities
                              select s.city_name;
            var namelist = suggestions.Where(n => n.ToLower().StartsWith(term.ToLower()));
            return Json(namelist, JsonRequestBehavior.AllowGet);
        }

If text is changed in States Textbox city autocomplete should be refilled.
Thanks.
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