开发者

how select second item az default in dropdownlist?

开发者 https://www.devze.com 2023-04-09 07:40 出处:网络
i have a dropdownlist, in mvc 3 razor: @Html.DropDownList( \"SelectedLicenses开发者_运维问答ID\",

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

精彩评论

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