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")
Cities Filter:
@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.