2012-07-16 109 views
-1

腳本ASP.NET Mvc下拉列表?

$(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;或其他錯誤有問題嗎?

謝謝。

+0

你能否提供你的路線?你也收到了什麼樣的錯誤? – 2012-07-16 09:33:48

回答

1

這是您的路由問題。使用「id」而不是「musteri_sno」來使用默認的地圖,或者在Global.asax.cs中添加一個更多的路由圖給你的控制器。

+0

我用id。謝謝,它的作品 – 2012-07-16 09:54:41