My dropdownlist is not selecting an item as expected (MVC 1)

Posted by Jen on Stack Overflow See other posts from Stack Overflow or by Jen
Published on 2011-01-11T23:46:48Z Indexed on 2011/01/11 23:54 UTC
Read the original article Hit count: 96

Filed under:
|

OK so I have 2 pages where this kind of behaviour is implemented. It works on one but doesn't work in another and I have no idea why. Despite the data containing a list of selectitems and one of them is selected the dropdown list is not displaying this selection (ie. it resets to the blank item).

I don't know how to further debug this.

In my page:

 <%= Html.DropDownList("CampusId", ViewData.Model.Campuses, new { @class = "large search_box" })%>

In my controller.

Campuses = AdminRepository
          .ListAll<Campus>(a => a.Description)
          .ToSelectListItem<Campus>(a => a.CampusId, a => a.Description, criteria.CampusId, true);

I can see that campuses does have the correct list item marked as selected - so why when it is displayed on the page is it no longer marked as selected?! I can't see anything else obviously modifying the list.

Thanks :)

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about asp.net-mvc