Html.DropDownList DisplayMemberPath SelectedItem
Posted on 2009-12-27
I'm using Visual Studio 2008 with .NET 3.5 SP1, and MVC. In one of my View, I've a DropDownBox named as "Source": "Source"'s DataSource property is binded to "Sources". Here: Sources is DTO which contains SourceId, Name, UpdatedDate, SourceType.
<%= Html.DropDownList("Source",new SelectList((IEnumerable) Model.Sources,"","Name",""))%>
I'm using DisplayMemberPath property to show ONLY "Name" (sourceName) in the dropdownBox.
My problem is HOW to get the selectedValue in the Controller?
I've tried: Source.SelectedItem, So0urce.SelectedValue, SelectedIndex.....but nothing gives us the selected value. Any help will be appreciated!!