如何根据以下代码设置SelectList/@Html.DropDownList的值?
- 控制器:
public ActionResult Edit(int id)
{
Order o = db.Orders.Find(id);
ViewBag.OrderStatusTId = new SelectList(db.OrderStatusTIds, "OrderStatusTId", "Name", o.OrderStatusTId); // I thought the last item would send in the selected item to the view?!?!?
return View(o);
}
- 景观:
@Html.DropDownList("OrderStatusTId", (IEnumerable<SelectListItem>)ViewBag.OrderStatusTId, String.Empty)
答案 0 :(得分:1)
使用viewdata代替viewbag并将帮助器更改为:
@ Html.DropDownList(“OrderStatusTId”,null,String.Empty)