2016-08-24 119 views
-1

我正在使用MVC模板,它有一個標準頁面創建按鈕的角色,但是當我單擊按鈕創建它時,會將我發送到登錄頁面,我無法登錄。我無法添加我需要的角色,因爲我需要管理員才能查看其他用戶的評估,並且用戶可以在頁面上看到他們自己的評估。我如何解決它?MVC添加角色並將它們添加到用戶

的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") 
} 
+0

什麼是您的方法授權'屬性? – Hadee

+0

我不明白你的意思。我沒有看到授權屬性? –

+0

你使用的是asp身份嗎? – Hadee

回答

0

你需要熟悉如何ASP.NET 5 Identity model作品。詳情請查詢here。然後檢查here知道如何創建User role

相關問題