Role enablement and basic usage in ASP. 2.2.0 (iv)

Source: Internet
Author: User
Tags actionlink

Create a role-dependent view

First step: Add view to open RolesAdminController.cs move mouse to public actionresult Index () Right-click Add View System will pop up dialog box nothing changes directly "OK"

Step two: Define a public enumeration model on the created view

Add @model ienumerable<microsoft.aspnet.identity.entityframework.identityrole> on the first line

The third step: Create a Page view template, after the code is completed as follows.

@model IEnumerable <microsoft. Aspnet.identity.entityframework.identityrole>@{Viewbag.title="List of roles";}@Html. ActionLink ("New Role","Create")</p><tableclass="Table"> <tr> <th>@Html. Displaynamefor (Model=model. Name)</th> <th> </th> </tr>@foreach (varIteminchModel) {        <tr> <td>@Html. Displayfor (ModelItem=item. Name)</td> <td>@Html. ActionLink ("Edit Role","Edit",New{id = Item.} Id}) |@Html. ActionLink ("Role Details","Details",New{id = Item.} Id}) |@Html. ActionLink ("Remove a role","Delete",New{id =item. ID})</td> </tr>    }</table>

Repeat the previous steps to complete the other view templates.

It is important to note that
1. A XXXX (project name) is defined at the top of the Create View template and the Edit view template. Models.roleviewmodel model.
2. A Microsoft.AspNet.Identity.EntityFramework.IdentityRole model is defined at the top of the delete view template and the Details view template.

The relevant code after completion is as follows:

Create View Template

@model xxxx (project name). models.roleviewmodel@{Viewbag.title="Create a role";}@using (Html.BeginForm ()) {@Html. AntiForgeryToken ()<divclass="Form-horizontal"> @Html. ValidationSummary (true)        <divclass="Form-group">@Html. Labelfor (Model= Model. Name,New{@class ="Control-label col-md-2" })            <divclass="col-md-10">@Html. Textboxfor (Model= Model. Name,New{@class ="Form-control"}) @Html. validationmessagefor (Model=model. Name)</div> </div> <divclass="Form-group"> <divclass="col-md-offset-2 col-md-10"> <input type="Submit"Value="Create" class="btn Btn-default"/> </div> </div> </div>}<div>@Html. ActionLink ("return to List of roles","Index")</div>@section Scripts {@Scripts. Render ("~/bundles/jqueryval")}


Edit View Template:

@model xxxx. models.roleviewmodel@{Viewbag.title="Edit Role";}@using (Html.BeginForm ()) {@Html. AntiForgeryToken ()<divclass="Form-horizontal"> @Html. ValidationSummary (true) @Html. Hiddenfor (Model=model. ID)<divclass="Form-group">@Html. Labelfor (Model= Model. Name,New{@class ="Control-label col-md-2" })            <divclass="col-md-10">@Html. Textboxfor (Model= Model. Name,New{@class ="Form-control"}) @Html. validationmessagefor (Model=model. Name)</div> </div> <divclass="Form-group"> <divclass="col-md-offset-2 col-md-10"> <input type="Submit"Value="Save" class="btn Btn-default"/> </div> </div> </div>}<div>@Html. ActionLink ("return to List of roles","Index")</div>@section Scripts {@Scripts. Render ("~/bundles/jqueryval")}

Details View Template:

@model microsoft.aspnet.identity.entityframework.identityrole@{viewbag.title="Role Details";}class="Dl-horizontal"> <dt>@Html. Displaynamefor (Model=model. Name)</dt> <dd>@Html. Displayfor (Model=model. Name)</dd> </dl></div>inch  ThisRole@if (Viewbag.usercount==0){    inch  ThisRole.</p>}<tableclass="Table">@foreach (varIteminchviewbag.users) {<tr> <td>@item. UserName</td> </tr>    }</table><p>@Html. ActionLink ("Edit Role","Edit",New{id = model.id}) |@Html. ActionLink ("return to List of roles","Index")</p>

Delete View Template:

@model microsoft.aspnet.identity.entityframework.identityrole@{viewbag.title="Remove a role";} ThisRole?  ThisRole would remove all users from  ThisRole. It'll not delete the users.</p><div> class="Dl-horizontal"> <dt>@Html. Displaynamefor (Model=model. Name)</dt> <dd>@Html. Displayfor (Model=model. Name)</dd> </dl>@using (Html.BeginForm ()) {@Html. AntiForgeryToken ()<divclass="form-actions No-color"> <input type="Submit"Value="Delete" class="btn Btn-default"/> |@Html. ActionLink ("return to List of roles","Index")        </div>    }</div>


At this point, the Roleadmin related view template is done.

Role enablement and basic usage in ASP. 2.2.0 (iv)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.