What is the alternative for autocomplete text changed event in MVC3

Posted by Sampath1750 under ASP.NET on 4/12/2012 | Points: 10 | Views : 2568 | Status : [Member] | Replies : 1
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.




Responses

Posted by: Mani5155 on: 4/12/2012 [Member] Starter | Points: 25

Up
0
Down
try jquery/ajax and wcf it will be easy one

refer it.... for further detail
http://www.dotnetfunda.com/codes/code2235-calling-wcf-using-ajax-and-jquery.aspx

Top Forums Authors
Thu, 19-Jan-2017 Authors
All Time Authors
Jayakumars
5420
Karthikanbarasan
3455
Oswaldlily
3290

Latest members | More ...


(Statistics delayed by 5 minutes)
Advertisements