2017-06-20 73 views
-1

我有數據庫表T_HD_FUNC有3個字段:FUNC_IDFUNC_NAMESYS_ID。在控制器我已經編寫此代碼:如何在asp.net中爲DropDownList添加多個屬性mvc

ViewBag.FUNC_ID = new SelectList(db.T_HD_FUNC.OrderBy(d => d.SORT), "FUNC_ID", "FUNC_NAME", "SYS_ID"); 

我已經編寫此代碼的視圖內:

@Html.DropDownList("FUNC_ID", (IEnumerable<SelectListItem>)ViewBag.Area_ID, "Select menu", new { @class = "form-control" }) 

其結果是:顯示值和名稱這樣圖像下方

但我想顯示filteridSYS_ID像這樣。

<option value="1" filterid = "1">Style master</option> 
<option value="2" filterid = "2">Styles Development</option> 
<option value="7" filterid = "1">Style Listing Gallery</option> 

因爲我想通過filterid過濾器組合框FUNC_ID當我選擇SYS_ID commbox。我不想再發布到服務器 我該怎麼辦? 由於使用這種

+0

你不能 - 對'的DropDownList()'方法只生成一個值屬性和基於文本的oneach'SelectListItem'(並且無論如何都是無效的HTML)。解釋你爲什麼要這樣做。 –

+0

[將屬性添加到選擇列表選項]的可能重複(https://stackoverflow.com/questions/11285303/add-attribute-to-select-list-option) – adiga

回答

0

$( 'yourElement')ATTR( 「yourAttribute」,yourValue)

相關問題