MVC添加角色并将其添加到用户

时间:2016-08-24 19:23:24

标签: .net asp.net-mvc view

我正在使用MVC模板,它有一个标准页面Roles with a button create,但是当我点击按钮创建它时,它会将我发送到我无法登录的登录页面。所以我无法添加我的角色需要因为我需要一个管理员来查看其他用户的评估,并且用户可以在页面上看到他们自己的评估。我该如何解决?

create.cshtml是这样的:

@model ASPNetMVCExtendingIdentity2Roles.Models.RoleViewModel
@{
ViewBag.Title = "Create";
}
<h2>Create Role</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()

<div class="form-horizontal">
    <h4>RolesViewModel</h4>
    <hr />
    @Html.ValidationSummary(true)

    @if (ViewBag.Message != "")
    {
        <p style="color: red">ViewBag.Message</p>
    }
    <div class="form-group">
        @Html.LabelFor(model => model.RoleName, new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.RoleName)
            @Html.ValidationMessageFor(model => model.RoleName)
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.Description, new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.Description)
            @Html.ValidationMessageFor(model => model.Description)
        </div>
    </div>

    <div class="form-group">
        <div class="col-md-offset-2 col-md-10">
            <input type="submit" value="Create" class="btn btn-default" />
        </div>
    </div>
</div>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}

1 个答案:

答案 0 :(得分:0)

您需要熟悉ASP.NET 5 Identity model的工作原理。有关详细信息,请查看here。然后查看here以了解如何创建User role

相关问题