0
我在其中一个模板中使用了下拉列表。从下拉列表项中选择一个值
@Html.DropDownListFor(m => m.LastName, Model.LastNames, new { id = "LastName" })
当显示下拉列表,如果我要预先选择从项目的下拉列表中的任何值,这怎么办呢?
我在其中一个模板中使用了下拉列表。从下拉列表项中选择一个值
@Html.DropDownListFor(m => m.LastName, Model.LastNames, new { id = "LastName" })
当显示下拉列表,如果我要预先选择从项目的下拉列表中的任何值,这怎么办呢?
在你的模型,你可以选择设定为true,像这样的姓氏列表...
List<SelectListItem> LastNames= new List<SelectListItem>();
items.Add(new SelectListItem
{
Text = "Jones",
Value = "Jones"
});
items.Add(new SelectListItem
{
Text = "Smith",
Value = "Smith",
Selected = true
});
items.Add(new SelectListItem
{
Text = "Johnson",
Value = "Johnson"
});