1
-- Controller --
[WebMethod]
public ActionResult GetSellers()
{
List<Seller> sellers = db.Sellers.ToList();
return Json(sellers, JsonRequestBehavior.AllowGet);
}
-- View --
@Html.DropDownList("SellerId", null, "-- Select --", htmlAttributes: new { @class = "form-control" })
-- 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>
Good afternoon,
The problem with this code is that when it is executed, there are no vendors that JSON returns, and yes, it returns 3 records, already debugged. What can be?
I switched here, but still not returning to me the records.
– developer033