In this article we will display a list of employees by creating a strongly typed view.
- Create a MVC project from the "Empty" template.
- Right-click on "Models", select "Add" >> "Class…".
Name the class "Employee" and click on the "Add" button.
In the employee class create employee properties like EmployeeId, FirstName, LastName and so on.
Now add a controller; right-click on "Controllers", select "Add" >> "Controller…".
Select "MVC 5 Controller - Empty" to add an empty controller. Click on the "Add" button.
Name the controller as in the following:
In the Index action result method:
Create a list of employees with some dummy employee details Assign the list to ViewData.Model
Now add a view. Right-click on the "Index" action method and select "Add View…".
Name the view as "Index".
Since we will show a list of employees, select "List" from the template. From the model class drop down, select "Employee" as model. Click on the "Add" button.
It will automatically create a view from the model.
Remove the "Create New" link from the top and The "Edit", "Details" and "Delete" links from the bottom of the table since we only want to display a list of employees.
Now run the project and you can have a list of employees in the browser.