The model class in the ASP.NET MVC system is covered in this section.
In an MVC application, model classes reflect domain-specific data and business logic. It uses public properties to represent data form and methods to represent business logic.
All Model classes in an ASP.NET MVC application must be built in the Model folder.
How to Add a Model Class?
Let's make a model class that contains the Student entity's necessary properties.
Right-click on the Model folder in Visual Studio's MVC application, select Add -> and then click on Class... The Add New Item dialogue box will appear.
Enter the class name Student in the Add New Item dialogue box and press Add.
In the model folder, this will create a new Student class. This model class will store the students' id, name, and age. So, as shown below, we'll need to add public properties for Id, Name, FatherName and Age.
public class Student
{
public int StudentId { get; set; }
public string StudentName { get; set; }
public string FatherName { get; set; }
public int Age { get; set; }
}
The model class can be used in the view to populate the data, as well as sending data to the controller.
This was a little introduction about models, hope you learned some basics from this blog apply it practically and then see my next blogs.
Happy Coding!

0 Comments