开发者

how select second item az default in dropdownlist?

i have a dropdownlist, in mvc 3 razor:

@Html.DropDownList(
       "SelectedLicenses开发者_运维问答ID",
            new SelectList(Model, "LicensesID", "LicenseUI"))

It contains 5 items. How can i set second item as the default item?


It depends, what's it's LicensesID value. If you know it you could:

@Html.DropDownList(
    "SelectedLicensesID",
    new SelectList(Model, "LicensesID", "LicenseUI", "123")
)

where 123 is the LicensesID of the item you want preselected.

Another possibility is to do this in the controller action:

public ActionResult Index()
{
    var model = ...
    // preselect the item that has LicensesID=123
    ViewData["SelectedLicensesID"] = "123";
    return View(model);
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜