0
我正在渲染一個下拉列表。ASP.NET MVC SelectList Select Option的值
ViewBag.Categories = new SelectList(db.HelpCategories, "ID", "Name");
在我看來,我這樣稱呼它:
Categories: @Html.DropDownList("Categories", (SelectList)ViewBag.Categories, "All")
對於我得到這樣選擇值。
<select id="Categories" name="Categories">
<option value="">All</option>
<option value="1">Dėl Krepšelių</option>
</select>
我真的需要將「全部」的值設置爲0。無法找到一種方法來做到這一點。找到一個教程,它使用SelectListItem完成,但不符合我的代碼。 任何幫助真的很感激,謝謝。
爲什麼你想將它設置爲'0'?如果你確實需要它,那麼你必須生成一個包含Value =「0」和Text =「All」的IEnumerable'(並且在你的DropDownList()方法中刪除第三個參數) –