How can i add autocomplete textbox changed event in MVC3

Posted by Sampath1750 under ASP.NET on 4/12/2012 | Points: 10 | Views : 1726 | Status : [Member] | Replies : 1
How can i add mvc3 Autocomplete textbox changed event. Below is my code.
my view code.

<div style="float: left">

States Filter :

</div>

<div style="float: left; padding-left: 10px">
@Html.TextBox("Statestxt")
</div>

<div style="padding-left: 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:**

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);
}



[AcceptVerbs(HttpVerbs.Post)]
public ActionResult States(state stateModel, string _stateName,
FormCollection formvalues)
{
AdmDataContext Adm = new AdmDataContext;

if (Request.Form["Statestxt"] == null)
{
ViewBag.Error = "Enter State Name.";
ViewData["name"] = false;

return View();
}
else
{
_stateName = Request.Form["Statestxt"].ToString();
var record = (from state in Adm.states
where state.state_name == _stateName
select state).Count();

if (record == 0)
{
ViewBag.Error = "Enter Valid State Name.";

return View();

}

var _Stateid = from state in Adm.states
where state.state_name == _stateName
select state;

int StateId = (int)_Stateid.First().state_id;
var state1 = am.FindUpcomingStates2(StateId).ToList();

if (state1 != null)
{
ViewData["name"] = true;
return View("States", state1);
}

}

}

I want to change the data after entering Statestext. Where i can write the code for Textbox changed event code.

Thanks.




Responses

Posted by: Sakthi.Singaravel on: 4/12/2012 [Member] Silver | Points: 25

Up
0
Down
Hi,

Refer this link,

http://stackoverflow.com/questions/8333020/mvc3-on-textbox-change-update-a-field-or-enable-save-button

Regards,
Singaravel M

Sampath1750, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response