Click here to Skip to main content
15,900,254 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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();
 }
Posted
Updated 10-Jan-19 8:24am
v2
Comments
Bryian Tan 10-Jan-19 17:19pm    
Any errors? and did you debug to see if the request hit the Getshipper() method? and if it did, is the return value null?
yogesh vaidya 11-Jan-19 0:27am    
Thanks sir,
i tried with debug with two breakpoints one for ViewBag.ContList = new SelectList(GetCustomer(), "CustomerID", "Customer_Name");

and second in public JsonResult Getshipper(int CustomerID)
it show Customer List well with chosen effect but i think he cant read $.getJSON("/Job/Getshipper",.....
i do lots of try to get this, i changed controller then changed html AddorEdit()
,
i am working in latest vs 2017 15.9.4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900