---
title: "Create A Simple Model in Asp.Net MVC 4 Application"  
description: "In this blog, I’m explaining how to create a simple model in asp.net mvc 4 application and how we can pass data using a model class.ExampleFirst creat"  
author: "Sumit Kesarwani"  
published: 2014-01-29  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/642/create-a-simple-model-in-asp-dot-net-mvc-4-application  
category: "asp.net mvc"  
tags: ["asp.net mvc"]  
reading_time: 3 minutes  

---

# Create A Simple Model in Asp.Net MVC 4 Application

In this blog, I’m explaining how to create a simple model in [asp.net mvc](https://www.mindstick.com/forum/155798/what-is-caching-in-asp-dot-net-mvc) 4 application and how we can [pass data](https://www.mindstick.com/forum/351/how-to-pass-data-from-controller-to-ascx-page) using a [model class](https://www.mindstick.com/forum/160267/what-is-the-role-of-the-range-data-annotation-and-when-to-use-it-in-a-model-class).

Example

First create an empty asp.net mvc 4 application with razor engine in [Visual studio](https://www.mindstick.com/articles/12378/visual-studio-for-mac-is-out-of-beta-preview-now-officially-available) 2012.

Adding a Model Class

In MVC, the M stands for model, and it is the most important part of the application. The model is the representation of the real-world objects, processes, and rules that define the subject, [known as](https://answers.mindstick.com/qa/35703/ricky-ponting-is-also-known-as-what) the domain, of our application. The model, often [referred to as](https://answers.mindstick.com/qa/39930/at-the-turn-of-the-century-widespread-panic-occurred-that-at-midnight-all-computers-would-reset-to-zero-and-life-as-we-knew-it-would-cease-to-exist-what-was-this-doomsday-theory-commonly-referred-to-as) a domain model, contains the C# objects (known as domain objects) that make up the universe of our application and the methods that let us manipulate them. The views and [controllers](https://www.mindstick.com/forum/155773/how-asynchronous-controllers-work-in-asp-dot-net-mvc) expose the domain to our clients in a consistent manner and a well-designed [MVC application](https://www.mindstick.com/forum/452/do-i-need-to-install-mvc-3-4-on-web-server-to-run-mvc-application) starts with a well-designed model, which is then the focal point as we add controllers and views.

Right click on the “Model Folder” in the solution explorer like this:

\

\

![Create A Simple Model in Asp.Net MVC 4 Application](https://www.mindstick.com/blogs/0bad9a67-1c68-4ed1-849f-45c848f10017/images/005589b3-6b3a-4dd1-a301-bd99f75dcbb0.png)

\

Click on the class option will open a pop-up like this:

![Create A Simple Model in Asp.Net MVC 4 Application](https://www.mindstick.com/blogs/0bad9a67-1c68-4ed1-849f-45c848f10017/images/09840943-1b2d-4c35-88a8-6bb8159f60d8.png)

\

Give the name “Student.cs” and click on Add button.

Visual studio will open the “Student.cs” file for editing:

```
using System;using System.Collections.Generic;using System.Linq;using System.Web;namespace SimpleModelApplication.Models{    public class Student    {    }}
```

Now add some [properties](https://www.mindstick.com/articles/23331/nootropics-7-different-types-and-their-unique-properties) in the Student.cs model class like this:

```
using System;using System.Collections.Generic;using System.Linq;using System.Web;namespace SimpleModelApplication.Models{    public class Student    {        public string studentID { get; set; }        public string studentName { get; set; }        public string studentAddress { get; set; }    }}
```

Next Step is to add a controller named it “HomeController.cs” and write the below code in it:

```
using SimpleModelApplication.Models;using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Mvc;namespace SimpleModelApplication.Controllers{    public class HomeController : Controller    {        //        // GET: /Home/        public ActionResult Index()        {            Student student = new Student();            student.studentID = "1001";            student.studentName = "Steve Benson";            student.studentAddress = "Washington DC";            return View(student);        }    }}
```

##### Now build the project.

Next step is to add a view to the project, right click on the index() in the HomeController.cs – a pop-up will open. Create a strongly-typed view and named it “Index.cshtml”.

##### Write the below code in “Index.cshtml” file:

```
@model SimpleModelApplication.Models.Student@{    Layout = null;}<!DOCTYPE html> <html><head>    <meta name="viewport" content="width=device-width" />    <title>Index</title></head><body>    <div>        Student ID : @Model.studentID<br />        Student Name : @Model.studentName<br />        Student Address : @Model.studentAddress     </div></body></html>
```

##### Output

Now run you application:-

![Create A Simple Model in Asp.Net MVC 4 Application](https://www.mindstick.com/blogs/0bad9a67-1c68-4ed1-849f-45c848f10017/images/443c6115-5ee0-4bb4-80d4-4fa0927c187a.png)

---

Original Source: https://www.mindstick.com/blog/642/create-a-simple-model-in-asp-dot-net-mvc-4-application

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
