Your question is hard to understand, but my best reasoning is that you're getting just a partial document rendered in the browser, without any layout, and you want the layout.
The reason for that is simply that you're return PartialView, which explicitly excludes layout. Instead, you need to return View like your actions are doing. Then, you should be using an actual view rather than your _UserList partial. In that view, you can call your partial:
@model List<ApplicationUser>
<partial name="_UserList" />
However, if I had to guess even further, I'd say that your ultimate goal is to have this user list rendered as part of your layout, while still being able to utilize other models/views. For that you should utilize a view component:
public class UserListViewComponent : ViewComponent
{
private readonly ApplicationDbContext _context;
public UserListViewComponent(ApplicationDbContext context)
{
_context = context;
}
public async Task<IViewComponentResult> InvokeAsync()
{
var userList = await _context.Users.Include(a => a.Departments).Include(a => a.Positions).ToListAsync();
return View(userList);
}
}
Then, create the view Views\Shared\Components\UserList\Default.cshtml, and add your HTML for rendering the list of users there (what is likely the content of _UserList.cshtml currently). Finally, add the following line where you want the list of users to appear:
@await Component.InvokeAsync("UserList")
@Html.Partial("_UserList")in your layout page, is it? - TanvirArjel