views:

943

answers:

1

Ok I have the following Code

   #region getDurationListDD
    private List<KeyValuePair<int, int>> getDurationListDD
    {
        get
        {
            List<KeyValuePair<int, int>> dDur = new List<KeyValuePair<int, int>>();
            dDur.Add(new KeyValuePair<int, int>(2, 2));
            dDur.Add(new KeyValuePair<int, int>(3, 3));
            dDur.Add(new KeyValuePair<int, int>(4, 4));
            dDur.Add(new KeyValuePair<int, int>(7, 7));
            dDur.Add(new KeyValuePair<int, int>(14, 14));
            dDur.Add(new KeyValuePair<int, int>(21, 21));

            return dDur;
        }
    }
    #endregion

Then the following in the main ActionResult...

ViewData["changeDuration"] = new SelectList(getDurationListDD, "Key", "Value", Duration);

this on the view

Html.DropDownList("changeduration", (SelectList)ViewData["changeDuration"])

Now if the Duration was set (i.e. int Duration = 7;) then I'd expect that 7 would be selected, but for some reason it isn't. Any hints before I give up trying and do something more productive?

Ta

+1  A: 

Just fixed it and I cant believe how retarded this is...

Changed Html.DropDownList("changeduration", (SelectList)ViewData["changeDuration"])

to

Html.DropDownList("cduration", (SelectList)ViewData["changeDuration"])

Problem Solved... that has to be a bug really doesn't it?

Chris M
You may have had some sort of ambiguous name in your view or your viewdata and by changing to "cduration" you disambiguated the value.
KP
Ye I'm guessing that the abiguous name was the use of changeDuration twice.
Chris M