trying to get Dropdownlist ,par not getting second list of shipper on CustomerID Param ,
What I have tried:
html ...
<div class="form-group">
<table>
<tr colspan="3">
<td>
@Html.LabelFor(Model => Model.CustomerName, new { @class = "Control-lable" })
@Html.DropDownListFor(m => m.CustomerID, ViewBag.ContList as SelectList, "Select Customer", new { @class = "form-control", @id = "Normal1" })
</td>
<td>
@Html.LabelFor(Model => Model.ShipperName, new { @clsss = "Control-label" })
@Html.DropDownListFor(m => m.ShipperID, new SelectList(" "), "-- Select Customer --", new { @class = "form-control" })
</td>
</tr>
</table>
</div>
</body>
</html>
@section Scripts{
<script src="~/Scripts/jquery-ui-1.10.2.min.js"></script>
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
<script>
$(document).ready(function () {
$("#CustomerID").change(function () {
$.getJSON("/Job/Getshipper", { CustomerID: $("#CustomerID").val() }, function (data) {
$("#ShipperID").empty();
$.each(data, function (index, row) {
$("#ShipperID").append("<option value='" + row.ShipperId + "'>" + row.Shipper_name + "</option>")
});
});
})
$(function () {
$("#Normal1").chosen()
});
});
</script>
}
Controller
public List<Customer> GetCustomer()
{
List<Customer> cust = dc.Customers.ToList();
return cust;
}
public JsonResult Getshipper(int CustomerID)
{
dc.Configuration.ProxyCreationEnabled = false;
List<Shipper> shippers = dc.Shippers.Where(x => x.CustomerID == CustomerID).ToList();
return Json(shippers, JsonRequestBehavior.AllowGet);
}
[HttpGet]
public ActionResult AddorEdit(int id=0 ,int CustomerID=0)
{
ViewBag.ContList = new SelectList(GetCustomer(), "CustomerID", "Customer_Name");
return View();
}
[HttpPost]
public ActionResult AddorEdit()
{
return View();
}