0
votes
  • Controller Code:

    List Months = new List();

            Months.Add("Jan");
            Months.Add("Feb");
    
        ViewData["Months"] = new SelectList(Months);
    
  • View Code:

${Html.DropDownList((SelectList)ViewData["Months"])}

Error: Argument 2: cannot convert from 'System.Web.Mvc.SelectList' to 'string'

1
What is List Months = new List();? I don't think that's valid c# - Forty-Two

1 Answers

0
votes

The error is pretty clear, it states that it expects a type of string and you are passing a SelectList make sure you use the correct overloads.

@Html.DropDownList("Months",selectList: ((SelectList)ViewData["Months"]))