2017-09-15 57 views
0

使用下拉列表在索引視圖中篩選記錄。如何從下拉列表中將xxxxxxx替換爲selectedValue進行過濾。我不知道如何從視圖中的下拉列表中選擇selectedValue。控制器代碼和視圖代碼如下。我知道它有一個小問題。但我試圖找到幾個小時。過濾器工作正常,如果我用xxxxxx替換1,2等。但我想從下拉列表中更改xxxxx與selectedValue。selectedValue從視圖到控制器MVC

控制器代碼

ViewBag.doctorsid = new SelectList(db.doctors, "doctorsid", "doctorsname",selectedValue); 
return View(appointments.Where(d => d.doctorsid == xxxxxxx).ToList()); 

視圖代碼

@Html.DropDownList("Doctorsid","Select Doctor") 
+0

顯示你的方法的簽名(其需求屬性'INT Doctorsid'綁定到)。但這是一種可怕的做法。將您的下拉列表綁定到模型屬性(請參閱[本答案](https://stackoverflow.com/questions/41719293/mvc5-how-to-set-selectedvalue-in-dropdownlistfor-html-helper/41731685#41731685)示例 –

回答

0

使用腳本波紋管給

Script

$("#Doctorsid").change(function() { 
    var doctorsid = $('#Doctorsid').val(); 
    var url = "/ControllerNmae/ActionResultName/+doctorsid ; 
    window.location.href = url; 
}); 
+0

正如你所建議的那樣,我做了一些小改動,包括javascript,但是這個值不是pkckedup。 – yesganesh

0

使用與列表中的變量模型第二下拉值,而不是直接通過列表來查看 控制器:

ViewBag.ClientTypeID = new SelectList(db.ClientType.Where(ct => ct.IsDeleted != true), "ID", "ClientTypeName"); 

查看:

@Html.DropDownListFor(m => m.ClientTypeID, new SelectList(ViewBag.ClientTypeList, "Value", "Text"), new { @class="drop"}) 
相關問題