Search code examples
c#htmlasp.netrazorhtml-helper

Adding default value DropDownList


From my controller I am sending the following List to my View.

    ViewBag.PROF= new SelectList(db.PROF.Where(y => y.USER_ID == user), "PROF_ID", "PROF_NAME");

When I display the above list in my View it gets displayed perfectly.

@Html.DropDownList("PROF", null, new { @class = "form-control" })

However, in the list that is been displayed I want to show the 3rd item as the default Item (or the item that will be displayed by default). How can I make this work ?


Solution

  • I believe a Selected value can be added to @Html.DropDownList. Simple mark the value you want as the default to be Selected = true and it'll be defaulted to that.