Last post Mar 10, 2009 12:42 PM by Eilon
Mar 08, 2009 06:00 PM|jonesie|LINK
I'm upgrading a beta project to RC2. DropDownList... sigh.
My controller code to create a SelectList looks like this:
ViewData["VenueID"] = getVenueSelectList(aValidGuidHere);
private SelectList getVenueSelectList(Guid venueid)
var vVar = from v
in DataContext.Venues orderby v.Name
List<Venue> vList = vVar.ToList<Venue>();
vList.Insert(0, new Venue());
vList.Name = "<None>";
vList.VenueID = Guid.Empty;
The view has this:
When I view an existing items I expect to see the appropriate item in the list selected, but it's not. So, as with the beta, I still have to use the following snippet of startup script:
$("select[@name='VenueID'] option[@value='<%= ViewData.Model.VenueID %>']").attr('selected',
Any I missing something here or is this still not fixed?
Mar 10, 2009 12:42 PM|Eilon|LINK
If the SelectList is stored in ViewData using the same key name as what you're using for your "name", then there is no need to manually extract the SelectList from ViewData. In other words, you can just say this in your view:
This should preserve any selected items that you had in the SelectList. I think there might very well have been a bug in the DropDownList code, but we felt that since there's a simple workaround we could postpone the bug fix.