Я пытаюсь создать модальное меню с вкладками, позволяющими переключаться между представлениями. Разумный подход, казалось, делал частичные представления и строил таблицу, используя для каждого оператора;Тем не менее, они в разных моделях, поэтому я борюсь. У меня есть первое представление, работающее в модальном режиме, но я не уверен, как использовать разные модели в каждом представлении.
@model PortalDev.Models.ViewModels.EditUserViewModel
<div class="modal-body">
<ul class="nav nav-tabs" id="myTab" role="tablist">
<li class="nav-item">
<a class="nav-link active" id="user-tab" data-toggle="tab" href="#user" role="tab" aria-controls="user" aria-selected="true">User</a>
</li>
<li class="nav-item">
<a class="nav-link" id="roles-tab" data-toggle="tab" href="#roles" role="tab" aria-controls="roles" aria-selected="false">Roles</a>
</li>
<li class="nav-item">
<a class="nav-link" id="claims-tab" data-toggle="tab" href="#claims" role="tab" aria-controls="claims" aria-selected="false">Claims</a>
</li>
</ul>
<div class="tab-content tabMenu" id="myTabContent">
@*----------------------Edit User Role Tab----------------------*@
<div class="tab-pane fade" id="roles" role="tabpanel" aria-labelledby="roles-tab">
<div class="wrapper">
<table class="table table-hover table-md ">
<thead>
<tr>
<td class="text-left TableHead">Id</td>
<td class="text-left TableHead">Role</td>
</tr>
</thead>
@*--Table Body For Each to pull DB records--*@
<tbody>
@foreach (var role in Model.Roles)
{
@Html.Partial("~/Views/Administration/Users/UserRoleTable.cshtml", role)
}
</tbody>
</table>
</div>
@*----------------------Edit User Claims Tab----------------------*@
<div class="tab-pane fade" id="claims" role="tabpanel" aria-labelledby="claims-tab">...</div>
</div>
</div>
</div>
------------------UserRoleTable.cshtml-------------------------------------
@model PortalDev.Models.ViewModels.ManageUserRoleViewModel
@{
ViewData["Title"] = "UserRoleTable";
}
<tr asp-action="ManageUserRoles" asp-controller="Administration" asp-route-id="@Model.RoleId">
<td class="text-left">@Model.RoleId</td>
<td class="text-left">@Model.RoleName</td>
</tr>
public class ManageUserRoleViewModel
{
public string RoleId { get; set; }
public string RoleName { get; set; }
public bool IsSelected { get; set; }
//Viewbag is used to store UserId
}
---------------EditUserVieModel.cs---------------
public class EditUserViewModel
{
public EditUserViewModel()
{
Claims = new List<string>(); Roles = new List<string>();
}
public string Id { get; set; }
[Required]
public string UserName { get; set; }
[Required]
[EmailAddress]
public string Email { get; set; }
public string City { get; set; }
public List<string> Claims { get; set; }
public IList<string> Roles { get; set; }
}
----------------AdministrationController.cs (method i need to call)----------
[HttpGet]
public async Task<IActionResult> ManageUserRoles(string userId)
{
ViewBag.userId = userId;
var user = await userManager.FindByIdAsync(userId);
if (user == null)
{
ViewBag.ErrorMessage = $"User with Id = {userId} cannot be found";
return View("NotFound");
}
var model = new List<ManageUserRoleViewModel>();
foreach (var role in roleManager.Roles)
{
var manageUserRoleViewModel = new ManageUserRoleViewModel
{
RoleId = role.Id,
RoleName = role.Name
};
if (await userManager.IsInRoleAsync(user, role.Name))
{
manageUserRoleViewModel.IsSelected = true;
}
else
{
manageUserRoleViewModel.IsSelected = false;
}
model.Add(manageUserRoleViewModel);
}
return View(model);
}
I have a users table... I want to be able to click on the user, get the edit modal to come up (works right now). Have 3 sub menu tabs on top. One for editing user info, Second for listing their Roles, Third for listing "claims".