问问题
37211 次
1 回答
59
DropDownListFor
如果要创建多选列表,则不要使用。你使用ListBoxFor
助手。
查看型号:
public class MyViewModel
{
public string[] SelectedIds { get; set; }
public IEnumerable<SelectListItem> Items { get; set; }
}
控制器:
public ActionResult Index()
{
var model = new MyViewModel
{
// preselect the first and the third item given their ids
SelectedIds = new[] { "1", "3" },
// fetch the items from some data source
Items = Enumerable.Range(1, 5).Select(x => new SelectListItem
{
Value = x.ToString(),
Text = "item " + x
})
};
return View(model);
}
看法:
@model MyViewModel
@Html.ListBoxFor(x => x.SelectedIds, Model.Items)
于 2011-12-08T17:08:57.967 回答