これはロールのコントローラーです。質問はフォームまたはビューから「Admins」という名前の役割を挿入するフォームを作成する方法です。事前のおかげでasp.net MVC 5ロールモデルのコントローラーとフォーム
public ActionResult CreateRole()
{
string Output = "";
ApplicationDbContext db = new ApplicationDbContext();
RoleManager<IdentityRole> RoleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(db));
if (!RoleManager.RoleExists("Admins"))
{
IdentityResult Result = RoleManager.Create(new IdentityRole("Admins"));
if (Result.Succeeded)
{
Output = "the role created";
}
else
{
int ErrorCount = Result.Errors.Count();
Output = "Errors is: " + Result.Errors.ToList()[0];
}
}
else
{
Output = "the roles exist";
}
return Content(Output);
}
このコードの問題は何ですか? –
問題はありません私はどのようにすることができますビューからこれを試す必要がありますか? @HakamFostok –