Having looked at the action verbs in the previous tutorial, in this section we will be looking at the model part of the MVC.

Models in the MVC world represents the domain data and business logic of our application. Model objects retrieves, modifies and helps in data persistence using a persistence store like a database.

Model data are decorated with properties which determines how the data are accessed. The model classes in the ASP.NET MVC lives in the Model folder.

To get started, let's see how to add a model class to an ASP.NET MVC project.

Adding a Model Class

Open our ActivitesHub project created in the previous tutorials in your Visual Studio. Right click on Model folder -> Add -> click on Class.

In the Add New Item dialog box, enter class name Activity and click Add.

asp.net models1
asp.net add new item

This will add new Activity class in model folder. Now, add Id, ActivityName, Description, Status properties as shown below.

Example: Model class

 public class Activity
        public int Id { get; set; }

        public string ActivityName { get; set; }

        public string Description { get; set; }

        public string Status { 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.

In the next tutorial we will look at yet another amazing feature of the ASP.NET MVC. Stay hunger, see you in the very next tutorial.

Inviting useful, relevant, well-written and unique guest posts