Create (Add) Model in Asp.Net MVC Application / Project

  Total Views : 3645
  Comments : 0
 
  Keywords : Create model in asp.net mvc application, Understand model in asp.net mvc, Adding model in asp.net mvc project,

Here we will learn what is model in asp.net mvc, use of model in asp.net mvc and how to create model in asp.net mvc application with example.

Create Model in Asp.Net MVC

The Model in asp.net mvc contains business logic and data. In asp.net mvc model is used to retrieve and store data in database. To add model in our asp.net mvc application Right click on Models folder à Select Add à then select Class like as shown following image

 

Add model to models folder in asp.net mvc application or project

 

When we click on class a new Dialog will pop up with name Add New Item in that select Class and give name as "Test" like as shown below

 

add new class as model in asp.net mvc folder

 

Once we provide name to our class as “Test” then click Add button once we add model that will contain code like as shown below

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

 

namespace Tutorial2.Models

{

public class Test

{

 

}

}

If we add properties to that model that would be like as shown below 

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

 

namespace Tutorial2.Models

{

public classTest

{

public int UserID { get; set; }

public string Username { get; set; }

public int Userage { get; set; }

public DateTime Userbirthdate { get; set; } 

}

}

This is how we will create model in our asp.net mvc application. 

 Comments (0)

Be the first to give your valuable feedback

Leave a comment

  • Default Tutlane User