MVC3 DropDownList + ViewBag issue

前端 未结 2 673
日久生厌
日久生厌 2020-12-03 13:30

This code works fine

List stateList = (from x in db.States
                                select new StateModelView {
                         


        
2条回答
  •  旧巷少年郎
    2020-12-03 13:51

    The ViewBag is a dynamic object, which cannot be used directly from your View (that is basically what the error is saying). You'll need to cast it:

    @Html.DropDownList("StateList", (SelectList) ViewBag.StateList)
    

    Another option would be to use ViewData though it may also require casting.

提交回复
热议问题