Great! Here's a little longer ASP.
NET Core MVC project that includes:
● Model
● Controller
● Views (Create, Read, Edit, Delete)
● Basic validation
● Tag Helpers
● In-memory list for data (no database for simplicity)
📘 Project Name: Task Tracker App
✅ Features:
● Add new task
● View all tasks
● Edit a task
● Delete a task
● Use Tag Helpers and Model Validation
🧱 Folder Structure
pgsql
CopyEdit
TaskTrackerApp/
│
├── Controllers/
│ └── [Link]
│
├── Models/
│ └── [Link]
│
├── Views/
│ └── Task/
│ ├── [Link]
│ ├── [Link]
│ ├── [Link]
│ └── [Link]
│
├── wwwroot/
├── [Link]
├── [Link] (if applicable)
└── [Link]
🔧 Step-by-Step Instructions
Step 1: Create Project
● Open Visual Studio
● Select [Link] Core Web App (MVC)
● Name: TaskTrackerApp
● Click Create
Step 2: Create the Model
📄 Models/[Link]
csharp
CopyEdit
using [Link];
namespace [Link]
{
public class TaskItem
{
public int Id { get; set; }
[Required]
public string Title { get; set; }
[Display(Name = "Is Completed")]
public bool IsCompleted { get; set; }
}
}
Step 3: Create the Controller
📄 Controllers/[Link]
csharp
CopyEdit
using [Link];
using [Link];
using [Link];
using [Link];
namespace [Link]
{
public class TaskController : Controller
{
static List<TaskItem> tasks = new List<TaskItem>();
public IActionResult Index()
{
return View(tasks);
}
public IActionResult Create()
{
return View();
}
[HttpPost]
public IActionResult Create(TaskItem task)
{
if ([Link])
{
[Link] = [Link] + 1;
[Link](task);
return RedirectToAction("Index");
}
return View(task);
}
public IActionResult Edit(int id)
{
var task = [Link](t => [Link] == id);
return View(task);
}
[HttpPost]
public IActionResult Edit(TaskItem updatedTask)
{
var task = [Link](t => [Link] ==
[Link]);
if (task != null && [Link])
{
[Link] = [Link];
[Link] = [Link];
return RedirectToAction("Index");
}
return View(updatedTask);
}
public IActionResult Delete(int id)
{
var task = [Link](t => [Link] == id);
return View(task);
}
[HttpPost, ActionName("Delete")]
public IActionResult DeleteConfirmed(int id)
{
var task = [Link](t => [Link] == id);
if (task != null)
{
[Link](task);
}
return RedirectToAction("Index");
}
}
}
Step 4: Create Views
📁 Views/Task/[Link]
html
CopyEdit
@model List<[Link]>
<h2>Task List</h2>
<a asp-action="Create">Add Task</a>
<table border="1">
<tr><th>ID</th><th>Title</th><th>Completed</th><th>Actions</th></tr>
@foreach (var task in Model)
{
<tr>
<td>@[Link]</td>
<td>@[Link]</td>
<td>@[Link]</td>
<td>
<a asp-action="Edit"
asp-route-id="@[Link]">Edit</a> |
<a asp-action="Delete"
asp-route-id="@[Link]">Delete</a>
</td>
</tr>
}
</table>
📁 Views/Task/[Link]
html
CopyEdit
@model [Link]
<h2>Add New Task</h2>
<form asp-action="Create" method="post">
<div>
<label asp-for="Title"></label>
<input asp-for="Title" />
<span asp-validation-for="Title"></span>
</div>
<div>
<label asp-for="IsCompleted"></label>
<input asp-for="IsCompleted" type="checkbox" />
</div>
<button type="submit">Save</button>
</form>
📁 Views/Task/[Link]
html
CopyEdit
@model [Link]
<h2>Edit Task</h2>
<form asp-action="Edit" method="post">
<input type="hidden" asp-for="Id" />
<div>
<label asp-for="Title"></label>
<input asp-for="Title" />
<span asp-validation-for="Title"></span>
</div>
<div>
<label asp-for="IsCompleted"></label>
<input asp-for="IsCompleted" type="checkbox" />
</div>
<button type="submit">Update</button>
</form>
📁 Views/Task/[Link]
html
CopyEdit
@model [Link]
<h2>Delete Task</h2>
<form asp-action="Delete">
<input type="hidden" asp-for="Id" />
<p>Are you sure you want to delete <b>@[Link]</b>?</p>
<button type="submit">Yes, Delete</button>
</form>
▶️ Run the App:
● Navigate to /Task
● Add, edit, and delete tasks
● Data will be lost on restart (in-memory only)