tags:

views:

52

answers:

2

I am having a bit of trouble with A dropdownlist that is supposed to be populated with values that correspond to ID keys in a database. So ideally i want something that looks like this in the dropdown list

value="0" USA value="1" ETC

and my code behind looks like this

    public TabletViewModel(Tablet tablet)
    {
        Tablet = tablet;
        //AreaHelper.Areas, tablet.Location.Name
        Areas = new SelectList(AreaHelper.Areas, tablet.Location.Name);
    }

whenever I try to add overflow methods to the selectlist constructor I get exception errors when I try to add the LocationID

anyone have any ideaS?

A: 

Does your list AreaHelper.Areas support IEnumerable?

Is tablet, tablet.Location or tablet.Location.Name Null?

Shiraz Bhaiji
the AreaHelper.Areas is an Ienumerable that returns the names of the areas, and the tablet.Location is a table of locations, and the tablet.Location.Name is not null, its the name associated with locationID, I just want the locationId to be the value associated with each option
Jimmy
+1  A: 

I figured out the issue, the IEnumerable i was passing was a specific column, not the whole table, so when i tried to do

new SelectList(AreaHelper.Areas, tablet.Location.Name, tablet.LocationID.ToString())

and got the error: "String doesn't contain property Name"

now everything is working fine

Jimmy