我有正确绑定 SelectListItem 与视图的问题。
项目控制器.cs
public ActionResult SelectCondition()
{
List<SelectListItem> items = new List<SelectListItem>();
items.Add(new SelectListItem { Text = "New", Value = "0", Selected=true });
items.Add(new SelectListItem { Text = "Old", Value = "1" });
var model = new Item
{
ItemCondition = items
};
return View();
}
创建.cshtml
@Html.DropDownList("SelectCondition", (IEnumerable<SelectListItem>)Model.ItemCondition)
物品.cs
public IEnumerable<SelectListItem> ItemCondition { get; set; }
现在我有NullReferenceException并在Create.cshtml中为这一行加了下划线