Introduction
This article is the continuation of the article “Adding Roles to Registration Razor Page in ASP.NET Core”. In this article, we will be working with users of the application that I created in the above-mentioned articles. So if it’s an employee or a customer, there will be a list of all the users. Here, the admin can see the list of users so they can select which user they want to work on a car. If an admin is working on a car, that car belongs to a user in this web application. We will be displaying the list of all of the available users.
Creating a list of users
We will create a user section in our spark automation web application which has been created in the above mentioned previous articles. We will add a new users tab at the top. When the user clicks on that tab, we can display a list of all of the users.
In order to create a new users tab, we have to make changes inside _layout.cshtml file.
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="utf-8" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
- <title>@ViewData["Title"] - SparkAutomation</title>
- <environment include="Development">
- <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.css" />
- </environment>
- <environment exclude="Development">
- <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
- </environment>
- <link rel="stylesheet" href="~/css/site.css" />
- </head>
- <body>
- <header>
- <nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
- <div class="container">
- <a class="navbar-brand" asp-area="" asp-page="/Index">SparkAutomation</a>
- <button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".navbar-collapse" aria-controls="navbarSupportedContent"
- aria-expanded="false" aria-label="Toggle navigation">
- <span class="navbar-toggler-icon"></span>
- </button>
- <div class="navbar-collapse collapse d-sm-inline-flex flex-sm-row-reverse">
- <partial name="_LoginPartial" />
- <ul class="navbar-nav flex-grow-1">
- <li class="nav-item">
- <a class="nav-link text-dark" asp-area="" asp-page="/Index">Home</a>
- </li>
- <li class="nav-item">
- <a class="nav-link text-dark" asp-area="" asp-page="/Privacy">Privacy</a>
- </li>
- <li class="nav-item">
- <a class="nav-link text-dark" asp-area="" asp-page="/Users/Index">Users</a>
- </li>
- </ul>
- </div>
- </div>
- </nav>
- </header>
- <div class="container">
- <main role="main" class="pb-3">
- @RenderBody()
- </main>
- </div>
- <footer class="border-top footer text-muted">
- <div class="container">
- © 2020 - SparkAutomation - <a asp-area="" asp-page="/Privacy">Privacy</a>
- </div>
- </footer>
- <environment include="Development">
- <script src="~/lib/jquery/dist/jquery.js"></script>
- <script src="~/lib/bootstrap/dist/js/bootstrap.bundle.js"></script>
- </environment>
- <environment exclude="Development">
- <script src="~/lib/jquery/dist/jquery.min.js"></script>
- <script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
- </environment>
- <script src="~/js/site.js" asp-append-version="true"></script>
- @RenderSection("Scripts", required: false)
- </body>
- </html>
Here, we will be go inside the users folder and add an index page, which we will create later in the article. The name of the tab is users.
Now, go to the solution explorer inside the pages folder. Right-click and add a new folder called users. Now right click on the users folder and add the above-mentioned index page.
In order to create an index page, add a new razor page called index and click on the add button to create an index razor page.
Inside the index razor page, we will be retrieving users from the database.


Join the conversation! Your thoughts help the community grow.