Blazor角色管理添加角色槽UI(Crud) [英] Blazor Role Management Add Role trough UI (Crud)
问题描述
我对blazor还是很陌生,并且对在数据库中添加角色有些怀疑.我已经实现了身份角色管理并拥有一个工作系统.但是现在我想通过GUI添加新角色,而不是编辑数据库.
I'm pretty new to blazor and have gotten myself in some doubt on adding roles to the database. I have implemented to Identity role management and have a working system. But now i want to add new roles trough the GUI instead of editing the database.
我有一个名为RolesOverview.razor的剃刀页面.在此页面上,我有一个输入字段和一个按钮.当我单击此按钮时,我想将文本添加到角色管理器并将其保存到数据库.
I have a razor page called RolesOverview.razor On this page i have a input field and a button. When i click this button i want to add the text to the roles manager and save it to the database.
这是我的剃须刀组件
@page "/admin/roles"
@using Microsoft.AspNetCore.Identity
@inject RoleManager<IdentityRole> roleManager
<div class="jumbotron">
<!-- Roles Overview Group Box -->
<div class="row mb-5">
<div class="col-12">
<h1 class="display-6">Roles Options</h1>
<hr class="my-4" />
<div class="row" style="background-color:white; margin-bottom:10px; margin-top:10px;">
<div class="col-12">
<div class="card w-100 mb-3" style="min-width:100%;">
<div class="card-body">
<h5 class="card-title">Roles</h5>
<p class="card-text">
<div class="row">
<div class="col-1">
Role Name:
</div>
<div class="col-10">
<input type="text" style="min-width:100%;" placeholder="Role Type" />
</div>
<div class="col-1">
<a href="#!" class="btn btn-primary" style="min-width:90px;">Add Role</a>
</div>
</div>
</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
未保存...
@code {
private string CurrentValue { get; set; }
private async void AddRole()
{
if (CurrentValue != string.Empty)
{
if (!await roleManager.RoleExistsAsync(CurrentValue))
{
await roleManager.CreateAsync(new IdentityRole
{
Name = CurrentValue
});
}
}
}
}
我不知道下一步该怎么做.我可以用剃须刀组件来做,还是需要在剃须刀页面上做?
I have no clue on what todo next. I's it posible todo it with razor component or do i need to do it trough razor page?
例子将是完美的.
关于我!
推荐答案
答案:
<div class="col-10">
<input value="@CurrentValue" @onchange="@((ChangeEventArgs __e) => CurrentValue =__e.Value.ToString())" />
@*<input type="text" style="min-width:100%;" placeholder="Role Type" />*@
</div>
<div class="col-1">
<a @onclick="AddRole" class="btn btn-primary" style="min-width:90px;">Add Role</a>
</div>
@code {私有字符串CurrentValue {get;放;}
@code { private string CurrentValue { get; set; }
private async void AddRole()
{
if (CurrentValue != string.Empty)
{
if (!await roleManager.RoleExistsAsync(CurrentValue))
{
await roleManager.CreateAsync(new IdentityRole
{
Name = CurrentValue
});
}
}
}
}
这篇关于Blazor角色管理添加角色槽UI(Crud)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!