我在控制器中创建一个selectList,以在视图中显示.
我正试图在飞行中创建它,有点像......这样......
myViewData.PageOptionsDropDown =
new SelectList(new [] {"10", "15", "25", "50", "100", "1000"}, "15");
Run Code Online (Sandbox Code Playgroud)
它编译,但输出不好......
<select id="PageOptionsDropDown" name="PageOptionsDropDown">
<option>10</option>
<option>15</option>
<option>25</option>
<option>50</option>
<option>100</option>
<option>1000</option>
</select>
Run Code Online (Sandbox Code Playgroud)
注意没有选择项目?
我怎样才能解决这个问题??
我正在研究MVC3 Web应用程序.我想要一个从应用程序管理系统编辑blo时显示的类别列表.在我的viewmodel中,我为类别的selectlistitems列表定义了以下属性.
/// <summary>
/// The List of categories
/// </summary>
[Display(Name = "Categorie")]
public IEnumerable<SelectListItem> Categories { get; set; }
Run Code Online (Sandbox Code Playgroud)
下一步,我的控制器包含以下编辑操作,其中从数据库中填充selectlistitems列表.
public ActionResult Edit(Guid id)
{
var blogToEdit = _blogService.First(x => x.Id.Equals(id));
var listOfCategories = _categorieService.GetAll();
var selectList = listOfCategories.Select(x =>new SelectListItem{Text = x.Name, Value = x.Id.ToString(), Selected = x.Id.Equals(blogToEdit.Category.Id)}).ToList();
selectList.Insert(0, new SelectListItem{Text = Messages.SelectAnItem, Value = Messages.SelectAnItem});
var viewModel = new BlogModel
{
BlogId = blogToEdit.Id,
Active = blogToEdit.Actief,
Content = blogToEdit.Text,
Title = blogToEdit.Titel,
Categories = selectList …Run Code Online (Sandbox Code Playgroud)