TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
osyris zosar
NA
289
27.7k
Trying to make a viewmodel with custom IdentityRole
Mar 26 2021 9:44 PM
Hello I am trying to create 2 tables one with users wich is already working and one with Roles
View: the bottom table is working well, only the "
applicationRoles
" is not
@model Test4.ViewModels.AdminDetailsViewModel
@{
ViewData[
"Title"
] =
"Index"
;
Layout =
"~/Views/Shared/_Layout.cshtml"
;
}
<h1>Index</h1>
<p>
<a asp-action=
"Create"
>Create New</a>
</p>
<table
class
=
"table"
>
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.applicationRoles[0].Id)
</th>
<th>
@Html.DisplayNameFor(model => model.applicationRoles[0].Name)
</th>
<th>
@Html.DisplayNameFor(model => model.applicationRoles[0].Description)
</th>
<th>
@Html.DisplayNameFor(model => model.applicationRoles[0].ConcurrencyStamp)
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.applicationRoles)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Id)
</td>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Description)
</td>
<td>
@Html.DisplayFor(modelItem => item.ConcurrencyStamp)
</td>
<td>
<a asp-action=
"Edit"
asp-route-id=
"@item.Id"
>Edit</a> |
<a asp-action=
"Details"
asp-route-id=
"@item.Id"
>Details</a> |
<a asp-action=
"Delete"
asp-route-id=
"@item.Id"
>Delete</a>
</td>
</tr>
}
</tbody>
<table
class
=
"table"
>
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.application[0].FirstName)
</th>
<th>
@Html.DisplayNameFor(model => model.application[0].LastName)
</th>
<th>
@Html.DisplayNameFor(model => model.application[0].Age)
</th>
<th>
@Html.DisplayNameFor(model => model.application[0].Password)
</th>
<th>
@Html.DisplayNameFor(model => model.application[0].UserName)
</th>
<th>
@Html.DisplayNameFor(model => model.application[0].Email)
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.application)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.FirstName)
</td>
<td>
@Html.DisplayFor(modelItem => item.LastName)
</td>
<td>
@Html.DisplayFor(modelItem => item.Age)
</td>
<td>
@Html.DisplayFor(modelItem => item.Password)
</td>
<td>
@Html.DisplayFor(modelItem => item.UserName)
</td>
<td>
@Html.DisplayFor(modelItem => item.Email)
</td>
<td>
<a asp-action=
"Edit"
asp-route-id=
"@item.Id"
>Edit</a> |
<a asp-action=
"Details"
asp-route-id=
"@item.Id"
>Details</a> |
<a asp-action=
"Delete"
asp-route-id=
"@item.Id"
>Delete</a>
</td>
</tr>
}
</tbody>
Application Role:
public
class
ApplicationRole : IdentityRole<Guid>
{
public
string Description { get; set; }
}
viewmodel:
public
class
AdminDetailsViewModel
{
public
List<ApplicationUser> application { get; set; }
public
List<ApplicationRole> applicationRoles { get; set; }
}
Controller:
public
async Task<IActionResult> Index()
{
var app = from m in _context.Users
select m;
var approle = from m in _context.UserRoles
select m;
var Admininfo =
new
AdminDetailsViewModel
{
application = await app.ToListAsync(),
applicationRoles = await approle.ToListAsync() // I get a error here
};
return
View(Admininfo);
}
Im not really sure how i should handle this
Reply
Answers (
2
)
Ajax not hitting controller
Export to pdf using Itextsharp in .NetCore