Basically this article would demonstrate in a step by step manner - how to populate a dropdown list in ASP.NET MVC2 using Entity Framework 4.0 using View Models and Repository Pattern.

Over the course of this article we will see how to Create View Model classes to make strongly typed Views and how to use Repository pattern in Models - to specify all the Querying methods required in the application.

1. Start by Creating a new Visual Studio Solution - Open a new instance of Visual Studio 2010.

Select File -> New -> Project and from the new project dialog select ASP.Net MVC 2 Web Application -> Name it -> PopulatingDDLusingEF

DrdolistMVC1.gif

Click Ok – and for this sample application -> Select -> "No, Do not create a unit Test Project"

2. Create ViewModel

3. Database Part

4. Setting up the Models

Adding Entity Framework classes

Creating a Repository Class

5. Views

6. Controllers

7. Compile and run the Project (F5)

DrdolistMVC6.gif

In this tutorial you have seen how to populate a dropdownlist in ASP.NET MVC by taking the advantage of Microsoft Entity Framework, ViewModel class and Repository pattern.

I have attached the Code for this Sample application.

Happy Learning!!