Model in MVC
In this section, you will learn about the Model in ASP.NET MVC framework.
Model represents domain specific data and business logic in MVC architecture. It maintains the data of the application. Model objects retrieve and store model state in the persistance store like a database.Model class holds data in public properties. All the Model classes reside in the Model folder in MVC folder structure.
Let's see how to add model class in ASP.NET MVC.
Adding a Model
Open our first MVC project created in
previous step in the Visual Studio. Right click on Model folder -> Add ->
click on Class.. In the Add New Item dialog box, enter class name 'Student' and click Add.
This will add new Student class in model folder. Now, add Id, Name, Addredss, Age, Gender properties as shown below.
For Example: Model class
namespace FirstMVCApplication.Models
{
public class Student
{
public int Student_Id { get; set; }
public string Name { get; set; }
public string Address{ get; set; }
public string Age { get; set; }
public string gender { get; set; }
}
}
So in this way, you can create a model class
which you can use in View. You will learn how to implement validations using
model later. namespace FirstMVCApplication.Models
{
public class Student
{
public int Student_Id { get; set; }
public string Name { get; set; }
public string Address{ get; set; }
public string Age { get; set; }
public string gender { get; set; }
}
}
Learn how to create a View in the next section
No comments: