开发者

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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜