Roles
3つのフィールドを持つテーブルがあります
Guid RoleId
string RoleName
string Description
私のregister.cshtml
見解では、テーブルdropdownlist
の RoleName のリストを表示する が必要です。Roles
また、ユーザーにロールを割り当てるなど、その値を取得して操作できるようにする必要があります。これはコントローラーで行われます。私のビューは現在、以下のように見えAspNetUser
ますRole
。dropdownlist.
@model Sorama.CustomAuthentiaction.Models.AspNetUser
@{
ViewBag.Title = "Register";
Layout = "~/Views/shared/_BootstrapLayout.empty.cshtml";
}
@section Styles{
<link href="@Url.Content("~/Content/bootstrap.css")" rel="stylesheet" type="text/css" />
}
<div class ="form-signin">
@using (Html.BeginForm("Register", "Account"))
{
@Html.ValidationSummary(true)
<h2 class="form-signin-heading"> Register </h2>
<div class ="input-block-level">@Html.TextBoxFor(model=>model.Email, new{@placeholder = "Email"})</div>
<div class ="input-block-level">@Html.TextBoxFor(model=>model.UserName, new{@placeholder = "UserName"})</div>
<div class ="input-block-level">@Html.PasswordFor(model=>model.Password, new{@placeholder ="Password"})</div>
<div class ="input-block-level">@Html.DropDownListFor(//don't know what to do
<button class="btn btn-large btn-primary" type="submit">Register</button>
}
</div>
私のコントローラは次のようになります
public class AccountController : Controller
{
//private readonly IDbContext dbContext;
//
// GET: /Account/
[HttpGet]
public ActionResult Login()
{
return View();
}
[HttpPost]
[AllowAnonymous]
public ActionResult Login(LoginModel model)
{
if(Membership.ValidateUser(model.UserName, model.Password))
{
FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
return RedirectToAction("Index", "Home");
}
ModelState.AddModelError("", "The user name or password provided is incorrect.");
return View(model);
}
[HttpGet]
public ActionResult Register()
{
string [] roles = Roles.GetAllRoles();
return View(roles);
}
[HttpPost]
public ActionResult Register(AspNetUser model)
{
return View();
}
public ActionResult Index()
{
return View();
}
}
そのドロップダウンリストを作成するには、どうすればよいですか?