Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Html.DropDownList DisplayMemberPath SelectedItem

Posted on 2009-12-27
Medium Priority
Last Modified: 2013-11-08
Hello there,

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!!

Question by:tech1guy
  • 2
LVL 11

Accepted Solution

lenordiste earned 2000 total points
ID: 26129139
Hi tech1guy, I ve not really used MVC but I see you are probably missing something in your SelectList constructor. The parameters are in order:
- source

since you are sending an empty string in your second parameter I assume this is the reason you are not getting anything through source.SelectedValue (which is what you need to call).
Try this:
<%= Html.DropDownList("Source",new SelectList((IEnumerable) Model.Sources,"SourceId","Name"))%>

Author Comment

ID: 26135155
I tried the solution that you suggested, but still I could NOT retrieve the selected value by user. Could someone please help me?

Author Closing Comment

ID: 31670259
It worked now.

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question