A list of “task questions” assigned (like tasks assigned to users, stored and shown in an ASP.NET Core app).
Let’s go step-by-step and build a “Task Question Assignment” feature in ASP.NET Core — showing how to fetch and display all assigned questions.
Concept: Task Question Assignment
Each task question is like a record assigned to a user — for example:
| QuestionId | QuestionText | AssignedTo | Status |
|---|
| 1 | What is ASP.NET Core Middleware? | Priya | Pending |
| 2 | Explain Entity Framework Core lifecycle. | Ramesh | Completed |
1. Create the Model
Models/TaskQuestion.cs
public class TaskQuestion
{
public int Id { get; set; }
public string QuestionText { get; set; } = "";
public string AssignedTo { get; set; } = "";
public string Status { get; set; } = "Pending";
public DateTime AssignedDate { get; set; } = DateTime.Now;
}
2. Add to DbContext
Data/AppDbContext.cs
using Microsoft.EntityFrameworkCore;
public class AppDbContext : DbContext
{
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) { }
public DbSet<TaskQuestion> TaskQuestions { get; set; }
}
3. Controller — Fetch Assigned Questions
Controllers/TaskQuestionController.cs
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System.Linq;
using System.Threading.Tasks;
public class TaskQuestionController : Controller
{
private readonly AppDbContext _context;
public TaskQuestionController(AppDbContext context)
{
_context = context;
}
// List all assigned task questions
public async Task<IActionResult> AssignedList()
{
var assignedQuestions = await _context.TaskQuestions
.Where(q => !string.IsNullOrEmpty(q.AssignedTo))
.OrderByDescending(q => q.AssignedDate)
.ToListAsync();
return View(assignedQuestions);
}
}
4. View — Display Assigned Task Questions
Views/TaskQuestion/AssignedList.cshtml
@model IEnumerable<TaskQuestion>
<h2> Assigned Task Questions</h2>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Question</th>
<th>Assigned To</th>
<th>Status</th>
<th>Assigned Date</th>
</tr>
</thead>
<tbody>
@foreach (var q in Model)
{
<tr>
<td>@q.QuestionText</td>
<td>@q.AssignedTo</td>
<td>@q.Status</td>
<td>@q.AssignedDate.ToString("dd-MMM-yyyy")</td>
</tr>
}
</tbody>
</table>
5. Example Output
| Question | Assigned To | Status | Assigned Date |
|---|
| Explain Middleware pipeline in ASP.NET Core | Ramesh | In Progress | 07-Nov-2025 |
| Describe Dependency Injection in ASP.NET Core | Priya | Pending | 08-Nov-2025 |
| What is EF Core Migration? | Sanjay | Completed | 06-Nov-2025 |
6. SQL Table Example
If you’re using SQL Server manually:
CREATE TABLE TaskQuestions (
Id INT PRIMARY KEY IDENTITY(1,1),
QuestionText NVARCHAR(500),
AssignedTo NVARCHAR(100),
Status NVARCHAR(50),
AssignedDate DATETIME DEFAULT GETDATE()
);
Optional Enhancements
| Feature | Description |
|---|
| Filter by User | Show questions assigned to a specific person |
| Update Status | Mark question as “Completed” |
| Notifications | Send email when a new question is assigned |
| Add Difficulty | Include “Level: Basic / Intermediate / Advanced” |
| Due Date | Add deadlines with reminders |
Example Filter by Logged-in User
You can modify the controller like this:
public async Task<IActionResult> MyTasks(string username)
{
var myTasks = await _context.TaskQuestions
.Where(q => q.AssignedTo == username)
.ToListAsync();
return View("AssignedList", myTasks);
}