相关疑难解决方法(0)

如何让这个ASP.NET MVC SelectList工作?

我在控制器中创建一个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)

注意没有选择项目?

我怎样才能解决这个问题??

c# asp.net-mvc selectlist

125
推荐指数
9
解决办法
22万
查看次数

C#mvc 3使用带有选定值的选择列表

我正在研究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)

c# asp.net asp.net-mvc asp.net-mvc-3

23
推荐指数
1
解决办法
7万
查看次数

标签 统计

asp.net-mvc ×2

c# ×2

asp.net ×1

asp.net-mvc-3 ×1

selectlist ×1