[go: up one dir, main page]

0% found this document useful (0 votes)
18 views4 pages

? Project Name - Student Record .Net MVC

The document outlines the creation of a Student Record project using ASP.NET Core MVC, allowing users to add and view student information. It details the steps to create the project, including setting up the model, controller, and views. The final section provides instructions on how to run the application and interact with the student records.

Uploaded by

gajndra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views4 pages

? Project Name - Student Record .Net MVC

The document outlines the creation of a Student Record project using ASP.NET Core MVC, allowing users to add and view student information. It details the steps to create the project, including setting up the model, controller, and views. The final section provides instructions on how to run the application and interact with the student records.

Uploaded by

gajndra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

📘 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!

You might also like