-- Controller --
[WebMethod]
public ActionResult GetSellers()
{
List<Seller> sellers = db.Sellers.ToList();
return Json(sellers, JsonRequestBehavior.AllowGet);
}
-- View --
@Html.DropDownListFor(x => x.SellerId, new SelectList(Enumerable.Empty<SelectListItem>()))
-- Javascript --
<script type="text/javascript">
$('#DeptId').change(function () { // DeptId is my another DropDownList
$.getJSON('/SaleRecords/GetSellers'), null, function (result) { // My path
var ddl = $('#SellerId'); // My seller DDL
ddl.empty();
$('Sellers').show(); // My div (it's display: none)
$(result).each(function () {
ddl.append(
$('<option />', {
value: this.Id
}).html(this.Name)
);
});
};
});
</script>
Why isn't the data showing up in my view even though I can see that the sellersList has 3 records in the controller? What could be causing this issue?