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";
- }
Index
- "Create">Create New
class="table">
- @Html.DisplayNameFor(model => model.applicationRoles[0].Id)
- @Html.DisplayNameFor(model => model.applicationRoles[0].Name)
- @Html.DisplayNameFor(model => model.applicationRoles[0].Description)
- @Html.DisplayNameFor(model => model.applicationRoles[0].ConcurrencyStamp)
- @foreach (var item in Model.applicationRoles)
- {
- @Html.DisplayFor(modelItem => item.Id)
- @Html.DisplayFor(modelItem => item.Name)
- @Html.DisplayFor(modelItem => item.Description)
- @Html.DisplayFor(modelItem => item.ConcurrencyStamp)
- "Edit" asp-route-id="@item.Id">Edit |
- "Details" asp-route-id="@item.Id">Details |
- "Delete" asp-route-id="@item.Id">Delete
- }
class="table">
- @Html.DisplayNameFor(model => model.application[0].FirstName)
- @Html.DisplayNameFor(model => model.application[0].LastName)
- @Html.DisplayNameFor(model => model.application[0].Age)
- @Html.DisplayNameFor(model => model.application[0].Password)
- @Html.DisplayNameFor(model => model.application[0].UserName)
- @Html.DisplayNameFor(model => model.application[0].Email)
Application Role:- @foreach (var item in Model.application)
- {
- @Html.DisplayFor(modelItem => item.FirstName)
- @Html.DisplayFor(modelItem => item.LastName)
- @Html.DisplayFor(modelItem => item.Age)
- @Html.DisplayFor(modelItem => item.Password)
- @Html.DisplayFor(modelItem => item.UserName)
- @Html.DisplayFor(modelItem => item.Email)
- "Edit" asp-route-id="@item.Id">Edit |
- "Details" asp-route-id="@item.Id">Details |
- "Delete" asp-route-id="@item.Id">Delete
- }
viewmodel:- public class ApplicationRole : IdentityRole
- {
- public string Description { get; set; }
- }
Controller:- public class AdminDetailsViewModel
- {
- public List
application { get; set; } - public List
applicationRoles { get; set; } - }
- public async Task
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 this2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions01ForumsTop experts
Arun PottiAnswers in the forums20answers02
Tahir AnsariAnswers in the forums5answers03
Kamlesh KumarAnswers in the forums5answers04
Sam HobbsAnswers in the forums4answers05
Željko PerićAnswers in the forums3answersFull leaderboard →
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Rijwan AnsariRank #82 · 24.2K reputationPosted Mar 27, 2021, 1:00 PM EDT
Satya KarkiRank #78 · 24.6K reputationPosted Mar 27, 2021, 1:01 PM EDT