-1
$(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>
行動
[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);
}
當我從MusteriSayaclariniGetir(int musteri_sno)
作用,除去參數musteri_no,我的代碼正常工作。 url var url = "/SayacOkumalari/MusteriSayaclariniGetir/" + strStateID;
或其他錯誤有問題嗎?
謝謝。
你能否提供你的路線?你也收到了什麼樣的錯誤? – 2012-07-16 09:33:48