1

I got a error for add role in my project. please any one help me.

Identity Config File (Role Manager)

 public class ApplicationRoleManager : RoleManager<IdentityRole>
    {
        public ApplicationRoleManager(IRoleStore<IdentityRole, string> roleStore)
            : base(roleStore)
        {
        }

        public static ApplicationRoleManager Create(IdentityFactoryOptions<ApplicationRoleManager> options, IOwinContext context)
        {
            //return new ApplicationRoleManager(new RoleStore<IdentityRole>(context.Get<ApplicationDbContext>()));
            return new ApplicationRoleManager(new RoleStore<IdentityRole>(new ApplicationDbContext()));
        }
    }

ConfigureAuth

app.CreatePerOwinContext<ApplicationRoleManager>(ApplicationRoleManager.Create);

Controller

private ApplicationRoleManager _roleManager;

public ApplicationRoleManager RoleManager
{
    get
    {
        return _roleManager ?? HttpContext.GetOwinContext().Get<ApplicationRoleManager>();
    }
    private set
    {
        _roleManager = value;
    }
}

Get Method

public ActionResult Register()
        {
            var model = new RegisterViewModel();
            model.RoleList = RoleManager.Roles.Select(c => c.Name).ToList();
            return View();
        }

View

    <div class="form-group">
        @Html.LabelFor(m => m.Role, new { @class = "col-md-2 control-label" })
        <div class="col-md-10">
            @Html.DropDownListFor(m => m.Role, new SelectList(Model.RoleList), new { @class = "form-control" })
        </div>
    </div>

Error enter image description here

Mmb shawon
  • 11
  • 1

0 Answers0