-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);
}

パラメータ musteri_no をMusteriSayaclariniGetir(int musteri_sno)アクションから削除すると、コードが正しく機能します。URLに問題がありvar url = "/SayacOkumalari/MusteriSayaclariniGetir/" + strStateID;ますか、それとも別のエラーですか?

ありがとう。

4

1 に答える 1

1

それはあなたのルーティングの問題です。"musteri_sno" の代わりに "id" を使用して、既定のマップを使用するか、Global.asax.cs でコントローラーのルーティング マップをもう 1 つ追加します。

于 2012-07-16T09:47:55.227 に答える