0
votes

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.OrderStatusTId, String.Empty)
1

1 Answers

1
votes

Use viewdata instead of viewbag and change your helper to:

@Html.DropDownList("OrderStatusTId",null, String.Empty)