@Html.DropDownList width

The second argument of the DropDownList helper must be an IEnumerable<SelectListItem>. You are passing a string (an empty one to be more precise). So in order to use this helper you will have to respect its signature:

@Html.DropDownList(
    "ListId", 
    Enumerable.Empty<SelectListItem>(), 
    new { style = "width: 250px;" }
)

Obviously generating an empty dropdown list is of little use. You probably have a view model (you should by the way) that you want to use to bind to:

@Html.DropDownList(
    "ListId", 
    Model.MyList, 
    new { style = "width: 250px;" }
)

and of course because you have a view model you should prefer to use the DropDownListFor helper:

@Html.DropDownListFor(
    x => x.ListId, 
    Model.MyList, 
    new { style = "width: 250px;" }
)

and finally to avoid cluttering your HTML with styles you should use an external CSS:

@Html.DropDownListFor(
    x => x.ListId, 
    Model.MyList, 
    new { @class = "mycombo" }
)

where in your external CSS you would define the .mycombo rule:

.mycombo {
    width: 250px;
}

Now you have what I consider a proper code.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)