---
title: "Model in ASP.NET MVC"  
description: "MVC model is basically a C# or VB.NET class. A model is accessible by both controller and view. A model can be used to pass data from controller to vi"  
author: "Chris Anderson"  
published: 2011-09-30  
updated: 2020-03-04  
canonical: https://www.mindstick.com/articles/753/model-in-asp-dot-net-mvc  
category: "asp.net mvc"  
tags: ["asp.net mvc"]  
reading_time: 2 minutes  

---

# Model in ASP.NET MVC

MVC model is basically a C# or VB.NET class. A model is accessible by both controller and view. A model can be used to [pass data](https://www.mindstick.com/forum/351/how-to-pass-data-from-controller-to-ascx-page) from controller to view. A view can use model to [display data](https://www.mindstick.com/forum/34030/how-to-display-data-in-the-table-using-angular-js) in page.Model objects are the parts of the application that implement the domain logic, also [known as](https://answers.mindstick.com/qa/38482/name-the-world-s-lightest-material-which-was-manufactured-by-isro-scientists-at-the-vikram-sarabhai-space-centre-thiruvananthapuram-and-is-also-known-as-blue-air) [business logic](https://answers.mindstick.com/qa/30543/what-is-business-logic). Domain logic handles the data that is passed between the database and the UI. For example, in an inventory system, the model keeps track of the items in storage and the logic to [determine whether](https://www.mindstick.com/forum/161622/how-do-you-determine-whether-a-file-is-locked-or-in-use-by-another-process) an item is in stock. In addition, the model would be the part of the application that updates the database when an item is sold and shipped out of the warehouse. Often, the model also stores and retrieves model state in a database.

We can add Model as depicted in a figure below:

##### Right Click on Model Folder Add a Class.

![Model in ASP.NET MVC](https://www.mindstick.com/mindstickarticle/b76e5898-693b-40d3-930b-a9220bda5b15/images/3c58f6f1-b002-4100-aa45-cfaf9a013d25.png)

After selecting Class option, change the class name if you want. Here I change it into ModelClass.cs\

##### Then click on Add button.

![Model in ASP.NET MVC](https://www.mindstick.com/mindstickarticle/b76e5898-693b-40d3-930b-a9220bda5b15/images/d08c750f-7cb5-4c43-aae6-274979d38d87.png)

After adding a class, you must also have to know the [functionality](https://www.mindstick.com/blog/136/using-watermark-functionality-in-textbox-by-jquery) of that class. In [Model class](https://www.mindstick.com/forum/2281/filter-objects-inside-model-class-by-date) we can implements properties, methods and validations attribute etc. according to our need. We can perform all the programming operation in the Class as we did earlier in various [programming languages](https://yourviews.mindstick.com/story/1911/7-programming-languages-you-can-learn-for-seo).

In this class I had created two properties i.e. FirstName and LastName. At the above of both property I also created various (Required, StringLength, [RegularExpression](https://www.mindstick.com/forum/160247/what-is-the-purpose-of-the-regularexpression-data-annotation)) attribute that put various validation on properties.Instead of properties and methods I also create a boolean method named IsExist\
that returns either [true or false](https://www.mindstick.com/forum/160329/how-can-you-convert-a-value-to-a-boolean-true-or-false-in-javascript) when invoked.

```
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.ComponentModel;using System.ComponentModel.DataAnnotations;  namespace FisrtMVCApp.Models{     public class ModelClass    {         [Required(ErrorMessage="First Name Required:")]         [DisplayName("Enter First Name:")]         [StringLength(30, ErrorMessage = ":Less than 30 characters")]         [RegularExpression(@"^[a-zA-Z'.\s]{1,40}$", ErrorMessage = "Special Characters                                                                            not allowed"                                                                        not allowed")]         public string FirstName         {            get;            set;         }          [Required(ErrorMessage = "First Name Required:")]         [DisplayName("Enter Last Name:")]         [StringLength(30, ErrorMessage = ":Less than 30 characters")]         [RegularExpression(@"^[a-zA-Z'.\s]{1,40}$", ErrorMessage = "Special Characters                                                                        not allowed"                                                                        not allowed")]         public string LastName         {            get;            set;         }           public bool IsExist()         {            return false;         }    }
```

By creating above Model class, we can understand and can easily implement the functionality of Model in MVC ASP.NET.

---

Original Source: https://www.mindstick.com/articles/753/model-in-asp-dot-net-mvc

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
