大家好我想問一個問題abuout mvc dropdownlist。我試圖過濾數據到他們的地方或他們的代碼,而下拉選擇索引更改。當我使用一個下拉菜單時,我可以做到這一點,但當我使用多個下拉菜單時,我無法單獨獲得結果。mvc控制兩個dropdownlist來過濾數據
正如你在圖片中看到的,我有兩個下拉列表。
public ActionResult Index(int? id,int? ddwList)
{
Repository<Order> _ro = new Repository<Order>();
IEnumerable<SelectListItem> _orderSelectListItem = _ro.All().AsEnumerable().Select(s => new SelectListItem
{
Text = s.code,
Value = s.id.ToString()
});
ViewData["ddOrder"] = _orderSelectListItem;
Repository<Workshop> _rw = new Repository<Workshop>();
IEnumerable<SelectListItem> _workshopSelectListItem = _rw.All().AsEnumerable().Select(s => new SelectListItem
{
Text = s.name,
Value = s.id.ToString()
});
ViewData["ddwList"] = _workshopSelectListItem;
Repository<ClothShipment> _rcs = new Repository<ClothShipment>();
IEnumerable<MyClothShipment> _myClothShipment = null;
if (id != null)
{
int? idOrd = _rcs.Find(w => w.orderId == id).orderId;
//int? idWork = _rcs.Find(w => w.workshopId == id).workshopId;
if (idOrd != null)
{
_myClothShipment = _rcs.All().Where(w => w.orderId == id).Select(s => new MyClothShipment
{
id = s.id,
amount = s.amount,
orderName = s.order.code,
clothName = s.clothList.name,
workshopName = s.workshop.name,
shipDate = s.shipDate
});
}
//else if(idWork != null){
// _myClothShipment = _rcs.All().Where(w => w.workshopId == id).Select(s => new MyClothShipment
// {
// id = s.id,
// amount = s.amount,
// orderName = s.order.code,
// clothName = s.clothList.name,
// workshopName = s.workshop.name,
// shipDate = s.shipDate
// });
//}
}
else {
_myClothShipment = _rcs.All().Select(s => new MyClothShipment
{
id = s.id,
amount = s.amount,
orderName = s.order.code,
clothName = s.clothList.name,
workshopName = s.workshop.name,
shipDate = s.shipDate
});
}
return View(_myClothShipment);
}
我的看法是這裏
<div id="sample_editable_2_length" class="dataTables_length">
<label>
@Html.DropDownList("ddwList",(IEnumerable<SelectListItem>)ViewData["ddwList"],"Atölye Seçiniz",new {@id="StateDropDown1", @class = "span15 chosen"})
</label>
</div>
我的看法是這裏
<div id="sample_editable_2_length" class="dataTables_length">
<label>
@Html.DropDownList("ddwList",(IEnumerable<SelectListItem>)ViewData["ddwList"],"Atölye Seçiniz",new {@id="StateDropDown1", @class = "span15 chosen"})
</label>
</div>
<div id="sample_editable_1_length" class="dataTables_length">
<label>
@*<select class="m-wrap small" name="sample_editable_1_length" size="1" aria-controls="sample_editable_1">
</select>*@
@Html.DropDownList("ddOrder",(IEnumerable<SelectListItem>)ViewData["ddOrder"],"Sipariş Kodu Seçiniz",new {@id="StateDropDown", @class = "span15 chosen"})
</label>
</div>
,這裏是我的腳本代碼
$("#StateDropDown").change(function (e) {
var controllerName = '@ViewContext.RouteData.Values["Controller"].ToString()';
var actionName = '@ViewContext.RouteData.Values["Action"].ToString()';
var _id = $("#StateDropDown").val();
var _url = "/" + controllerName + "/" + actionName + "/" + _id;
window.location.href =_url
});
$("#StateDropDown1").change(function (e) {
var controllerName = '@ViewContext.RouteData.Values["Controller"].ToString()';
var actionName = '@ViewContext.RouteData.Values["Action"].ToString()';
var _id = $("#StateDropDown1").val();
var _url = "/" + controllerName + "/" + actionName + "/" + _id;
window.location.href = _url
});
我填充從數據庫加載頁面時的下拉列表,並獲取所有數據以顯示下拉列表我想過濾顯示的數據...並使用此代碼我的下拉列表中的一個我選取了選定的ID item(Index(int? ID))在這裏,但當我嘗試分別使用它們兩個它不工作,我怎麼能讓他們兩個工作。我該怎麼辦 ?第二個參數總是爲空,或者如果我使用不同的參數,除了「id」它再次變爲空?而且我試圖把參數作爲字符串,但它也是空的...謝謝你的幫助。
感謝您的回答,但是那不是我找 – nalpara