Roles Provider - AccountModel

Posted by Jemes on Stack Overflow See other posts from Stack Overflow or by Jemes
Published on 2010-05-01T12:54:11Z Indexed on 2010/05/01 12:57 UTC
Read the original article Hit count: 215

Filed under:

I'm adding the Roles provider to the built in AccountModel but having some problems adding GetAllRoles in my view using the Register View Model.

View Model from AccountModel

public class RegisterModel
    {
        UserName, Email Etc....

        [Required]
        [DisplayName("AllRoles")]
        public SelectList AllRoles { get; set; }
    }

Roles Service added to AccountModel

public interface IRolesService
{
    SelectList GetAllRoles();
}

    public class RolesService : IRolesService
{
    public SelectList GetAllRoles()
    {
        var AllRoles = new SelectList(Roles.GetAllRoles());
        return AllRoles;
    } 
}

Register View Page Inherits RegisterModel

           Form...

            <div class="editor-label">
                <%= Html.LabelFor(m => m.ConfirmPassword) %>
            </div>
            <div class="editor-field">
                <%= Html.PasswordFor(m => m.ConfirmPassword) %>
                <%= Html.ValidationMessageFor(m => m.ConfirmPassword) %>
            </div>

            <%= Html.DropDownListFor(m => m.AllRoles)%>

I'm not sure how to populate the DropDown list with all the Roles from the View Model.

Any help would be really great!!

© Stack Overflow or respective owner

Related posts about asp.net-mvc