---
title: "Simple Way of Binding List of Objects to View using MVC"  
description: "I would like to show list of users on HTML page using MVC. I am assuming you are aware from MVC."  
author: "Devesh Omar"  
published: 2014-05-21  
updated: 2019-09-07  
canonical: https://www.mindstick.com/articles/1403/simple-way-of-binding-list-of-objects-to-view-using-mvc  
category: "asp.net"  
tags: ["asp.net"]  
reading_time: 3 minutes  

---

# Simple Way of Binding List of Objects to View using MVC

Simple Way of Binding List of Objects to View using MVC

**[Introduction](https://yourviews.mindstick.com/view/85450/mesopotamia-introduction-to-an-ancient-civilization)**

I would like to show list of users on HTML page using MVC. I am assuming you are aware from MVC.

## Following would be Steps

**1)** **Adding Model**

We have added UserModel.cs inside Models folder.

It has username, age and Gender as properties. Various attributes has been defined for validations

![Simple Way of Binding List of Objects to View using MVC](http://www.mindstick.com/MindStickArticle/703d7d51-a911-480e-b8e9-75d95052d3d6/Images/image001.png)

**2)** **Adding Controller.**

Using Right click on controller folder and we added UserController.cs.

![Simple Way of Binding List of Objects to View using MVC](http://www.mindstick.com/MindStickArticle/703d7d51-a911-480e-b8e9-75d95052d3d6/Images/image003.png)

We have added UserContoller.cs inside Controller folder and Created DisplaUserDetails() Method. Inside this method we created a list of users and passed to view.

Here list of users basically are the list of UserModel

List<UserModel> listuser = new List<UserModel>();

UserModel users = new UserModel();

users.UserName = "Devesh Omar";

users.Age = 12;

users.Gender = "M";

listuser.Add(users);

users = new UserModel();

users.UserName = "Ram Kumar";

users.Age = 12;

users.Gender = "M";

listuser.Add(users);

return View(listuser); // here we are [passing data](https://www.mindstick.com/interview/34053/passing-data-into-components-in-knockout) to view.

Here in last line we are passing List of users to View using View(listuser), because our aim is to display list of users at View page.

**3)** **Adding View**

a) Right Click on DisplayUserDetails() and Click on **Add View..**

![Simple Way of Binding List of Objects to View using MVC](http://www.mindstick.com/MindStickArticle/703d7d51-a911-480e-b8e9-75d95052d3d6/Images/image004.png)

b) After clicking on Add View We will get following screen.

![Simple Way of Binding List of Objects to View using MVC](http://www.mindstick.com/MindStickArticle/703d7d51-a911-480e-b8e9-75d95052d3d6/Images/image006.png)

· Select Checkbox ”Strongly-typed view”

· Select “UserModel” from [View Data](https://www.mindstick.com/forum/159852/view-data-from-database-using-mvc-entity-framework) class dropdown

· Select “List” from View content dropDown.

· Then click on Add button.

4) Now after step 3, we will have [strongly typed](https://www.mindstick.com/forum/298/strongly-typed-view-in-mvc) View, having name = DisplayUserDetails.aspx

5) Here in MVC arch we do not have any code – behind file.\
\

6) Folder having name “User” automatically created.

We have folder having name = User because we created Controller having name= **User**Controller.

![Simple Way of Binding List of Objects to View using MVC](http://www.mindstick.com/MindStickArticle/703d7d51-a911-480e-b8e9-75d95052d3d6/Images/image008.png)

**7)** **Modifying [Global.asax](https://www.mindstick.com/interview/33579/what-are-those-event-handlers-that-can-be-in-the-global-asax-file)**

We have some [default settings](https://answers.mindstick.com/qa/95596/how-do-i-reset-firefox-to-default-settings) at Global.asax file; we need to modify it to following code.

public static void [RegisterRoutes](https://www.mindstick.com/forum/12655/registerroutes-not-working-in-mvc5)(RouteCollection routes)

{

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

routes.MapRoute(

"Default", // Route name

"{controller}/{action}/{id}", // URL with parameters

new { controller = "User", action = "DisplayUserDetails", id = UrlParameter.Optional } // Parameter defaults

);

}

Following are modifications.

a) action = "DisplayUserDetails"

b) controller = "User"

8) Running the [application](https://www.mindstick.com/articles/12824/calculator-application-in-android) and following would be output.

![Simple Way of Binding List of Objects to View using MVC](http://www.mindstick.com/MindStickArticle/703d7d51-a911-480e-b8e9-75d95052d3d6/Images/123.png)

## Conclusion

It is very simple way to [bind data](https://www.mindstick.com/forum/415/how-to-bind-data-in-windows-phone-7-using-wcf-service) from model to view.

Inside code of controller we can modify the code as per our [requirements](https://www.mindstick.com/articles/12850/drivers-license-requirements) like we can have database call and then we can fill list of users from data base. Then we can pass list of users to view for display.

---

Original Source: https://www.mindstick.com/articles/1403/simple-way-of-binding-list-of-objects-to-view-using-mvc

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
