In My MVC Controller, Can I Add a Value to My HTML.DropDownList?

Posted by Aaron Salazar on Stack Overflow See other posts from Stack Overflow or by Aaron Salazar
Published on 2010-04-06T01:32:28Z Indexed on 2010/04/06 1:33 UTC
Read the original article Hit count: 377

Filed under:
|
|

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

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about html