Models represent the data used by your application. They are one of the core parts of MVC. In ASP.NET Core, models often describe real-world objects such as students, products, books, or customers.
public class Student
{
public int Id { get; set; }
public string Name { get; set; }
public string Course { get; set; }
public int Age { get; set; }
}
This model represents a student object. Each property holds one piece of student information.
A controller can create a model object and pass it to a view:
public IActionResult Details()
{
Student student = new Student
{
Id = 1,
Name = "Alice",
Course = "Computer Science",
Age = 21
};
return View(student);
}
The view must declare the model type first:
@model Student@Model.Name
Course: @Model.Course
Age: @Model.Age
Data binding is the process by which ASP.NET Core automatically maps incoming form data to model properties. This makes form handling much easier.
For example, if a form contains input fields named Name, Course, and Age,
ASP.NET Core can bind those values directly to a Student object.
[HttpPost]
public IActionResult Create(Student student)
{
return View(student);
}
Models are essential because they give your application a structured way to work with data. Data binding makes the interaction between forms and models simple and efficient.