locked
Trying to make a viewmodel with custom IdentityRole RRS feed

  • Question

  • User1750806012 posted
    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 
    Saturday, March 27, 2021 12:55 AM

All replies

  • User475983607 posted

    What is the error? 

    Saturday, March 27, 2021 11:15 AM