Search code examples
asp.net-mvcrazordropdownlistfor

DropDownListFor with no item


I have two DropDownListFors. With changing the first one's selected item, the second one's list changes. There's no problem til here.

The problem is I want the second list to be empty before the first change of the first DropDownListFor. How can I do this?

In short, how can I have a DropDownListFor with no items at first?


Solution

  • I think I found it. It was so simple. :)

    @Html.DropDownListFor( model => model.Student,
        new List<SelectListItem>() {
            new SelectListItem() { Text = "", Value = "" }
        })