script
$(document).ready(function () {
$("#musteri_sno").change(function () {
var strSayacID = "";
strSayacID = $(this)[0].value; // get the selected state id
var url = "/SayacOkumalari/MusteriSayaclariniGetir/" + strSayacID ;
// call controller's action
$.getJSON(url, null, function (data) {
// do something once the data is retrieved
$("#sayac_no").empty();
$.each(data, function (index, optionData) {
$("#sayac_no").append("<option value='"
+ optionData.sno
+ "'>" + optionData.sayac_seri_no
+ "</option>");
});
});
})
.change(); // making sure the event runs on initialization for default value
});
html
<td>
@Html.DropDownList("musteri_sno", (SelectList)ViewBag.musteri_id, "--Müşteri Seçiniz--", new { id = "musteri_sno" })
</td>
<td>
@Html.DropDownList("sayac_no", Enumerable.Empty<SelectListItem>(), "-- Sayaç Seçiniz --", new { id = "sayac_no" })
</td>
action
[HttpGet]
public ActionResult MusteriSayaclariniGetir(int musteri_sno)
{
var sites = entity.TblSayaclar.Where(x => x.musteri_id == musteri_sno).Select(x => new { sno = x.sno, sayac_seri_no = x.seri_no });
return Json(sites, JsonRequestBehavior.AllowGet);
}
When I removed parameter musteri_no from MusteriSayaclariniGetir(int musteri_sno) action, my codes work correctly. Is there a problem with url var url = "/SayacOkumalari/MusteriSayaclariniGetir/" + strStateID; or different error?
Thanks.
It’s a problem of your routing. Use “id” instead of “musteri_sno” to use the default map or add one more routing map for your controller in Global.asax.cs