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);
}
精彩评论