ASP.NET MVC: What is the difference between model and Model?

In this post we will answer one of the doubts that some people have when developing web applications with ASP.NET MVC: What is the difference between model and Model?

When we develop an ASP.NET MVC application, if we go to a view that uses a model, we can see that at the top of the view it says something like:

@model Person

This code indicates that the type of data of the model to be used in the view is Person. Which means that in our solution we have a class called Person, which represents the type of data of the model of our view. Of course, we are not limited to using classes. We can use primitive types. For example, we could use an integer:

@model int

Now, one thing is the type of data, and another thing is the data per se. The variable where the model of our view is stored is called: Model.

So, in the case that the data type of the model is Person, if the Person class has a property called Age, then I can write:

@Model.Age

To write the value of the age of the model that was sent to the view by the controller.

TL; DR

model => data type

Model => the data itself

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s