1

In my ASP MVC site I want to be able to select a default drop down list item in the view. However, the overload I'm currently using seems to just add another item to the drop down list instead of specifying which one I want selected.

Here is the code in the controller that created the SelectList

SelectList tmpList = new SelectList(new[] { "", "SAF", "SNY" });
ViewBag.Companies = tmpList;

And here is the code in the view. This, however, just winds up adding an extra SAF to the list like the screen shot below shows.

@Html.DropDownListFor(model => model.AgencyCompany1, (SelectList)ViewBag.Companies, "SAF")

enter image description here

NealR
  • 10,189
  • 61
  • 159
  • 299

1 Answers1

0

You can try this in your controller, where the second "SAF" is where you are setting the selected object:

ViewBag.list = new SelectList(new[] { "", "SAF", "SNY" }, "SAF");

And in your view (you don't need the last "SAF" parameter anymore):

@Html.DropDownListFor(model => model.AgencyCompany1, (SelectList)ViewBag.Companies)