I found a solution that works for me. I have a .Net core MVC app using identity. I have a method in my controller where I get the Id of the user that's logged in.
[HttpGet]
public IActionResult UserIndex()
{
var userId = _userManager.GetUserId(HttpContext.User);
List<Assign> listdata = _context.Assign.Where(u => u.Id == userId).ToList();
return View(listdata);
}
View:
@model IEnumerable<TaskManager2.Models.Assign>
@{
ViewData["Title"] = "UserIndex";
}
<h1>UserIndex</h1>
<p>
<a asp-action="Create">Create New</a>
</p>
<table class="table">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.TaskId)
</th>
<th>
@Html.DisplayNameFor(model => model.Id)
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.TaskId)
</td>
<td>
@Html.DisplayFor(modelItem => item.Id)
</td>
<td>
<a asp-action="Edit" asp-route-id="@item.AssignId">Edit</a> |
<a asp-action="Details" asp-route-id="@item.AssignId">Details</a> |
<a asp-action="Delete" asp-route-id="@item.AssignId">Delete</a>
</td>
</tr>
}
</tbody>
</table>
Hope it helps sb!