在我看来,我有一个HTML DropDownList,在我的控制器中使用List<string>
填充。在我的MVC控制器中,我可以向我的HTML.DropDownList添加一个值吗?
<%= Html.DropDownList("ReportedIssue", (IEnumerable<SelectListItem>)ViewData["ReportedIssue"]) %>
List<string> reportedIssue = new List<string>();
reportedIssue.Add("All");
reportedIssue.Add(...);
ViewData["ReportedIssue"] = new SelectList(reportedIssue);
在我看来,其结果是:
<select name="ReportedIssue" id="ReportedIssue">
<option>All</option>
<option>...</option>
</select>
有没有办法做到这一点,还包括在每一个<option>
标签像这样的价值呢?
<select name="ReportedIssue" id="ReportedIssue">
<option value="0">All</option>
<option value="1">...</option>
</select>
谢谢
亚伦
我不会使用ViewData ...我会使用ViewModel。 – Martin 2010-09-02 01:55:03
@Martin我同意这一点,但这不是'必要的',只是一个好习惯:) – Kelsey 2010-09-02 03:43:38