Problem with ASP.NET MVC DropDownList not displaying selected value
Posted
by Jova
on Stack Overflow
See other posts from Stack Overflow
or by Jova
Published on 2010-01-30T11:24:09Z
Indexed on
2010/06/18
10:53 UTC
Read the original article
Hit count: 304
I have an aspx page which allows me to edit articles. Among things I can edit is which category the article belongs to. The category is chosen through a DropDownList as shown here,
<%= Html.DropDownList("categoryID", (IEnumerable<SelectListItem>)ViewData["CategoryID"], new { @class = "textbox" }) %>
However, the articles category isn't selected when I go to that page. The ViewData I use for the DropDownList looks like this,
ViewData["CategoryID"] = new SelectList(categories, "CategoryID", "Title", article.CategoryID);
Which should select the article.CategoryID as it's selected value. Have I done this wrong?
© Stack Overflow or respective owner