Introduction
In this article, you will see how to add multiple Dropdown Lists in the Web API. Here we create two dropdown lists, one for employee name and another is for the employee's address.
The following is the procedure for creating the application.
Step 1
Create a Web API application.
- Start Visual Studio 2012.
- From the Start window select "New project".
- Then Select "Installed" -> "Visual C#" -> "Web"
- Select "MVC4 Web Application" and click on the "OK" button.

- From the "MVC4" window select "Web API".

- Click on the "OK" button.
Step 2
Create a Model class using the following procedure:
- In the "Solution Explorer".
- Right-click on the "Model" -> "Add" -> "Class".
- Select "Installed" -> "Visual C#".

- And then select "Class" and click on the "OK' button.
Add the following code:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- namespace MultipleDrop.Models
- {
- public class Detail
- {
- public SelectList EmployeeList { get; set; }
- public SelectList AddressList { get; set; }
- }
- public class Employee
- {
- public int ID { get; set; }
- public string EmployeeName { get; set; }
- }
- public class Emp_Address
- {
- public int ID { get; set; }
- public string Address { get; set; }
- }
- }
Step 3
Select the "HomeController".
-
In the "Solution Explorer".
-
Expand the "Controller" folder.
-
Select the "Home Controller".

Add the following code:



Comments
Join the conversation! Your thoughts help the community grow.