How do I set the value of a SelectList/@Html.DropDownList given the following code?
--Controller:
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);
}
--View:
@Html.DropDownList("OrderStatusTId", (IEnumerable<SelectListItem>)ViewBag.Or开发者_StackOverflowderStatusTId, String.Empty)
Use viewdata instead of viewbag and change your helper to:
@Html.DropDownList("OrderStatusTId",null, String.Empty)
精彩评论