Overview
In this article, we will see what models are in MVC Application. Suppose, we want to retrieve a student’s information from the students table. The table given below follows, where we have to display its corresponding Id, Name, Gender and City as.
| Id | 1 |
| Name | Akshay |
| Gender | Male |
| City | Mumbai |
We want an output in a tabular format.
To retrieve information, we need to have student model class. Add a class file in Models folder, name it as Students.cs and assign the container properties to it, as given below.

Now, add a controller, name it as StudentController and change the action method from Index to Details as.

We want the details, which should be retrieved from the database. At the moment, we will hard code the values and in the later articles, we will see how to retrieve the details from the database.
Thus, import the models namespace, so that we can use StudentsClass, which is placed inside our models folder as.

As you can see, we had hard coded the values here, as we need to hand over this object to the view and our view will display its various details.
Thus, add a view as Details.
Now, we have to bind the various details like Id, name, city, gender to our model as.

View Code is given below.
- @model ModelsInMVCApp.Models.Students
- @{
- ViewBag.Title = "Details";
- }
- <h2>Details</h2>
- <table style="font-family:Arial">
- <tr>
- <td>
- <b> id:</b>
- </td>
- <td>
- @Model.id
- </td>
- </tr>
- <tr>
- <td>
- <b> Name:</b>
- </td>
- <td>
- @Model.name
- </td>
- </tr>
- <tr>
- <td>
- <b> Gender:</b>
- </td>
- <td>
- @Model.gender
- </td>
- </tr>
- <tr>
- <td>
- <b> city:</b>
- </td>
- <td>
- @Model.city
- </td>
- </tr>
- </table>

Now, save the solution and run the app. We will get the output as-

We had got expected output.
Conclusion
Thus, the controller responds to the URL requests, gets the data from the model and hands it over to the view. The view then renders the data. Model can be entities or business objects.
Thus, this was Models in MVC Application. Hope, this article was helpful!!

Priyanka KalePosted Feb 17, 2018, 2:08 AM
Brilliant article.
SubashPosted Oct 23, 2016, 9:29 PM
How can we retrive from backend(database)
SubashPosted Oct 23, 2016, 9:28 PM
I have one doubt how we do it for more than one rows
SubashPosted Oct 23, 2016, 9:28 PM
Thank you very useful