I have a dropdownlist and a textbox in my page,I want to change the dropdownlist with the textbox change. I use JQuery post like this:
$("#txtBuildId").change(function() {
var builddate = $("#txtBuildId").val();
$.post("/UTOverview/Index?builddate=" + builddate);
});
and my Index function is:
public ActionResult Index()
{
string buildDate = Request.Params.Get("builddate");
DataTable tbBuildid = DatabaseService.getBuilidByDate(buildDate);
List<SelectListItem> list = new List<SelectListItem>();
foreach (DataRow bd in tbBuildid.Rows as IEnumerable)
{
list.Add(new SelectListItem { Text = bd["buildid"].ToString(), Value = bd["buildid"].ToString() });
}
ViewData["tbbuildid"] = list;
return View();
}
But I found that the dropdownlist didn't change with the DataView["tbbuildid"] change? Why ?
I try to do this via full postback way like: window.location = "/UTOverview/Index?builddate=" + builddate; It works. ViewData["tbbuildid"] changed every time I post the new builddate to the method index.But how can I do this by Ajax way?