The following code has worked in v1.3 but not 1.4 I can’t seem to figure out what the issue is. I’m building a cities ddl from a selection from the province ddl. I’m using ASP.NET MVC 2
The function on the server gets called and it builds up the correct list, but when it returns it never steps into the callback function. I’ve put in some alerts, and the don’t get called. except for the one before the getJSON
Anyone know what I’m doing wrong?
$(function () {
var provinces = $("#ProvinceId");
var cities = $("#CityId");
provinces.change(function () {
cities.find('option').remove();
alert("hello outside JSON call");
$.getJSON('<%= Url.Content("~/HomeController/Cities") %>', { province: provinces.val(), includeAllPlaceholder : true }, function (data) {
alert("hello");
$(data).each(function () {
alert("hello 2");
$("<option value=" + this.Value + ">" + this.Text + "</option>").appendTo(cities);
alert(this.Value + ":" + this.Text);
});
});
});
});
in the controller
public JsonResult Cities(string province, bool includeAllPlaceholder)
{
List<SelectListItem> items = new List<SelectListItem>();
int provinceId;
if (int.TryParse(province, out provinceId))
{
var values = ReferenceTableService.CitiesInProvince(provinceId).Where(f => includeAllPlaceholder || (includeAllPlaceholder == false && f.IsAllPlaceholderEntry == false)).ToList();
values.Sort();
items.Add(new SelectListItem { Value = "", Text = Resources.Global.Generic.ddlSelectValue });
items.AddRange(values.Select(f => new SelectListItem { Value = f.Id.ToString(), Text = f.Name }));
}
return Json(items);
}
thanks
TR
thanks for all the help folks. turns out I needed to add in
JsonRequestBehavior.AllowGetto my return statement*sigh