📘 Project Name: Student Record
✅ Purpose:
Allow users to:
● Add a student's name and course.
● View all students.
🔧 Steps to Create
Step 1: Create Project
● Open Visual Studio
● Select: ASP.NET Core Web App (Model-View-Controller)
● Name it: StudentRecord
● Click Create
Step 2: Create Model
📄 Models/Student.cs
csharp
CopyEdit
namespace StudentRecord.Models
{
public class Student
{
public int Id { get; set; }
public string Name { get; set; }
public string Course { get; set; }
}
}
Step 3: Create Controller
📄 Controllers/StudentController.cs
csharp
CopyEdit
using Microsoft.AspNetCore.Mvc;
using StudentRecord.Models;
using System.Collections.Generic;
using System.Linq;
namespace StudentRecord.Controllers
{
public class StudentController : Controller
{
static List<Student> students = new List<Student>();
public IActionResult Index()
{
return View(students);
}
public IActionResult Create()
{
return View();
}
[HttpPost]
public IActionResult Create(Student s)
{
s.Id = students.Count + 1;
students.Add(s);
return RedirectToAction("Index");
}
}
}
Step 4: Create Views
📁 Views/Student/Index.cshtml
html
CopyEdit
@model List<StudentRecord.Models.Student>
<h2>Student List</h2>
<a asp-action="Create">Add Student</a>
<table border="1">
<tr><th>ID</th><th>Name</th><th>Course</th></tr>
@foreach (var s in Model)
{
<tr>
<td>@s.Id</td>
<td>@s.Name</td>
<td>@s.Course</td>
</tr>
}
</table>
📁 Views/Student/Create.cshtml
html
CopyEdit
@model StudentRecord.Models.Student
<h2>Add Student</h2>
<form asp-action="Create" method="post">
<label>Name</label>
<input asp-for="Name" /><br />
<label>Course</label>
<input asp-for="Course" /><br />
<button type="submit">Save</button>
</form>
▶️ How to Run:
● Set StudentController as start page in launchSettings.json or navigate to
/Student
● Press Ctrl + F5
● Add and view students easily!