【发布时间】:2011-04-05 23:38:58
【问题描述】:
这是什么鬼? MVC3 的 DropDownList 中是否存在某种错误? SelectedValue 未显示为标记中实际选择的值。
我正在尝试不同的方法,但没有任何效果。
public class SessionCategory
{
public int Id { get; set; }
public string Name { get; set; }
}
public static IEnumerable<SessionCategory> Categories
{
get
{
var _dal = new DataLayer();
return _dal.GetSesionCategories();
}
}
@{
var cats = Infrastructure.ViewModels.Session.Categories;
var sl = new SelectList(cats, "Id", "Name",2);
}
@Html.DropDownList("categories", sl);
【问题讨论】:
-
你能确认 cat 变量中确实有类别吗?
标签: c# asp.net-mvc-3 drop-down-menu