开发者

asp.net mvc html.dropdownlist error

开发者 https://www.devze.com 2023-01-05 18:23 出处:网络
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.HtmlH

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("Userrol开发者_StackOverflow社区e",((SelectList)ViewData["Roles"]).Items,"--Select One---") %>
                </p>


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---") %>


controller code

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

it is your view code you try this it is working fine

<%: Html.DropDownList("Userrole", ViewData["z"] as SelectList,"--selectone--")%>
0

精彩评论

暂无评论...
验证码 换一张
取 消