ASP.NET - problem in binding dropdownlist - Asked By aman on 14-Mar-12 02:39 AM

hi all,

 i am using Asp.net mvc 3 and below goes the code i have used to bind the dropdown list

controller......
 public ActionResult aaaaa()
{
        string[] reasonForRemoval = new[] { "Left Company", "No Longer in Role" };
        List<SelectListItem> itemsReasonForRemoval = new SelectList(reasonForRemoval).ToList();
        ViewData["ReasonForRemoval"] = itemsReasonForRemoval;
return view();
}

and below goes my view code....
          <td class="dropdown">
            <%: Html.DropDownList("ReasonForRemoval")%>
          </td>

please help me it is not getting binded....

Thanks,
[)ia6l0 iii replied to aman on 14-Mar-12 03:29 AM
If ViewData is set as the model for the view, then you can refer to the ViewData value from the Model. Something like, 
@Html.DropDownListFor(model => model.ReasonForRemoval, Model)...

If ViewData is not the model for the view, 
<%: Html.DropDownList("name", ViewData["ReasonForRemoval"] as List<string>)%>