0

Hi I have passed list items as select list in view from controller .

other data are retrieved from database

  var pairList = new List<KeyValuePair<String, Int32>>();
        var pair = new KeyValuePair<string, int>("Daily", 0);
        pairList.Add(pair);
        pair = new KeyValuePair<string, int>("Weekly", 7);
        pairList.Add(pair);
        //pair = new KeyValuePair<string, int>("Bi-Weekly", 14);
        //pairList.Add(pair);
        pair = new KeyValuePair<string, int>("Monthly", 30);
        pairList.Add(pair);

        ViewBag.frequency = new SelectList(pairList, "Value", "Key", null);

and it view i was to display selected value while page loads .

by some working I get the selected value like 7 or 30 etc from other functional which is also dynamic

 <td id="testa">                                          
  @Html.DropDownList("testddl", ViewBag.frequency as SelectList)
</td>

How can I set selected value .

Thnaks Binaya

Binayacharya
  • 94
  • 1
  • 10
  • possible duplicate of [dropdownlist set selected value in MVC3 Razor](http://stackoverflow.com/questions/6807256/dropdownlist-set-selected-value-in-mvc3-razor) – Rowan Freeman Apr 29 '14 at 02:32
  • Similar but i want to achieve using viewbag as select list not pass as model with selected option ? – Binayacharya Apr 29 '14 at 03:07
  • Are you able to provide a reason for your approach? Using the `ViewBag` makes things more difficult and complex. – Rowan Freeman Apr 29 '14 at 06:37

0 Answers0