Pre-Selecting a value for a dropdownbox
As the title says really
<td><%= Html.DropDownList("Weight", Model.Weightddl.Select(x => new SelectListItem { Text = x.Name, Value = x.Id.ToString() }))%><开发者_Go百科;/td>
Here is my line of code. I have the value Model.Weight which I want to have preselected on the load... How can I set it as the selected value?
thanks
Steve
Set the Selected
property, like this:
<td><%= Html.DropDownList("Weight",
Model.Weightddl.Select(x => new SelectListItem {
Text = x.Name,
Value = x.Id.ToString(),
Selected = (x.Id == Model.Weight)
}))%></td>
精彩评论