In My MVC Controller, Can I Add a Value to My HTML.DropDownList?
- by Aaron Salazar
In my view I have an HTML DropDownList that is filled, in my controller, using a List<string>.
<%= Html.DropDownList("ReportedIssue", (IEnumerable<SelectListItem>)ViewData["ReportedIssue"]) %>
List<string> reportedIssue = new List<string>();
reportedIssue.Add("All");
reportedIssue.Add(...);
ViewData["ReportedIssue"] = new SelectList(reportedIssue);
In my view the result is:
<select name="ReportedIssue" id="ReportedIssue"><option>All</option>
<option>All</option>
<option>...</option>
</select>
Is there a way to do this and also include a value in each of the <option> tags like so?
<select name="ReportedIssue" id="ReportedIssue"><option>All</option>
<option value="0">All</option>
<option value="1">...</option>
</select>
Thank you,
Aaron