views:

21

answers:

1

CS1928: 'System.Web.Mvc.HtmlHelper' does not contain a definition for 'DropDownList' and the best extension method overload 'System.Web.Mvc.Html.SelectExtensions.DropDownList(System.Web.Mvc.HtmlHelper, string, string)' has some invalid arguments

I am getting the user roles form the memebership provider and then asking the user to select the role. the roles are in a dropdown list on the register page.

public ActionResult ChangePassword() 
        {

            ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
            var roles = Roles.GetAllRoles().ToList();       
            ViewData["Roles"] = new SelectList(roles);

            return View();
        }

<p>
               <%= Html.DropDownList("Userrole",((SelectList)ViewData["Roles"]).Items,"--Select One---") %>
                </p>
A: 

Try

  <%= Html.DropDownList("Userrole",((SelectList)ViewData["Roles"]),"--Select One---") %>

update

There is something else that is causing the issue(do you have other extensions for the DropDownlist?)

The following works for me:

Action

 public ActionResult About()
        {
            var x = new List<string>
            {
                "A", "B", "C"
            };
            var y = new SelectList(x);
            ViewData["z"] = y;
            return View();
        }

View

 <%= Html.DropDownList("Userrole",((SelectList)ViewData["z"]),"--Select One---") %>
Raj Kaimal
It's giving me this error when i dont have thatException Details: System.InvalidOperationException: There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'Userrole'.
Pinu
see update above.
Raj Kaimal
I copy pasted and ran the same code that you sent me , it still throws the above error.
Pinu
Sorry ,I got it , I made the changes as your code and it looks good now. Thank You so much Raj , appreciate your help.
Pinu