---
title: "How to pass multiple dropdown list values from view to controller and saving into a database?"  
description: "How to pass multiple dropdown list values from view to controller and saving into a database?"  
author: "Ailsa Singh"  
published: 2017-05-04  
updated: 2017-05-04  
canonical: https://www.mindstick.com/forum/34288/how-to-pass-multiple-dropdown-list-values-from-view-to-controller-and-saving-into-a-database  
category: "database"  
tags: ["sql"]  
reading_time: 3 minutes  

---

# How to pass multiple dropdown list values from view to controller and saving into a database?

I am having difficulty in passing [multiple](https://www.mindstick.com/blog/12797/iowa-is-expected-to-see-heavy-growth-in-multiple-sectors) [dropdown list](https://www.mindstick.com/forum/760/dropdown-list-open-hide-behind-another-dropdown-list-on-ie-7) [values](https://www.mindstick.com/forum/327/sum-textbox-values) from [view to controller](https://www.mindstick.com/forum/34314/post-data-from-view-to-controller-using-ajax) and [saving](https://www.mindstick.com/blog/11865/guide-to-saving-15-for-retirement) [data](https://www.mindstick.com/articles/13050/salesforce-aiming-to-dominate-predictive-analytics-with-data-science) into a database. Please help me.Thanks in advance.

## Replies

### Reply by Manish Kumar

\

First we create database and table

Countrylist table for first [dropdown](https://www.mindstick.com/articles/263/ajax-toolkit-dropdownextender-in-asp-dot-net)

\

```
CREATE TABLE [dbo].[Country](          [Id] [int] IDENTITY(1,1) primary key NOT NULL,          [Country] [varchar](50) NULL,          )
```

DistrictList table

```
CREATE TABLE [dbo].[District](          [Id] [int] IDENTITY(1,1) primary key NOT NULL,          [District] [varchar](50) NULL,          )
```

\

And Statelist table

```
CREATE TABLE [dbo].[State](          [Id] [int] IDENTITY(1,1) primary key NOT NULL,          [State] [varchar](50) NULL,          )
```

And Registrationform table

```
 CREATE TABLE [dbo].[Registration](          [Id] [int] IDENTITY(1,1) primary key NOT NULL,          [Name] [varchar](50) NULL,          [Country] [varchar](50) NULL,          [State] [varchar](50) NULL,          [District] [varchar](50) NULL,          [Address] [varchar](50) NULL,)
```

Now add New Project and Right Click on the Models folder and select Ado.Net Entity Data Model

\

![How to pass multiple dropdown list values from view to controller and saving into a database?](https://www.mindstick.com/mindstickforums/741b3b1d-4c0b-4581-80cb-9a666552ef19/images/4e081599-7743-4907-bf45-a3455886d434.png)\

\

And the click generate From Database

\

![How to pass multiple dropdown list values from view to controller and saving into a database?](https://www.mindstick.com/mindstickforums/741b3b1d-4c0b-4581-80cb-9a666552ef19/images/7f4b16ca-877c-47df-9cdf-ef45e88d2139.png)\

\

\

And next and then give connection information and select your database.

\

\

![How to pass multiple dropdown list values from view to controller and saving into a database?](https://www.mindstick.com/mindstickforums/741b3b1d-4c0b-4581-80cb-9a666552ef19/images/cf686428-6788-4d5d-a49b-a6d12495444b.png)\

\

\

Then choose tables and then finish.

In the next step we will create Home Controller for adding controller right click on the controllers folder and go to add and then click controller then a pop up will be appear from here you can change you can give your controller name .

\

![How to pass multiple dropdown list values from view to controller and saving into a database?](https://www.mindstick.com/mindstickforums/741b3b1d-4c0b-4581-80cb-9a666552ef19/images/bc4dd68f-c131-4b84-95de-035a208e03f7.png)\

\

\

\

\

In the [controller](https://www.mindstick.com/blog/273/passing-values-from-controller-to-view-in-asp-dot-net-mvc) copy the following code.

```
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Mvc;using System.Data;using MvcApplication4.Models; namespace MvcApplication4.Controllers{   
public class HomeController : Controller   
{       
//       
// GET: /Home/        
public ActionResult Index()       
{            var
context = new DropdownEntities();            ViewBag.country = context.Countries;            ViewBag.state = context.States;            ViewBag.district =
context.Districts;            return View();                   
}       
[HttpPost]       
public ActionResult Add(Registration Model)       
{            using(var context=new DropdownEntities())            {               
context.Registrations.Add(Model);                context.SaveChanges();            }            var
context1 = new DropdownEntities();            ViewBag.country =
context1.Countries;            ViewBag.state = context1.States;            ViewBag.district =
context1.Districts;            return View("Index");       
}    
}} 
```

\

And in the [view](https://yourviews.mindstick.com/view/84701/layoffs-in-google-india-2023-view)

\

```
 @model MvcApplication4.Models.Registration@{   
Layout = null;} <!DOCTYPE html> <html><head>   
<meta name="viewport" content="width=device-width" />   
<title>Index</title>   
<style>       
select {       
width:200px}       
input {       
width:200px}            input[type="Submit"] {                color:blue;                width:80px;            }       
fieldset {            width:500px;            margin-left:250px;       
}   
</style></head><body>   
<div>      
@using (Html.BeginForm("Add","Home",FormMethod.Post))      
{                      
<fieldset>               <legend><strong>Registration Form</strong></legend>          
<table>               <tr><td>                   Name:                  @Html.TextBoxFor(x=>x.Name)</td>                   <td>Country:@Html.DropDownListFor(x =>
x.Country, new SelectList(ViewBag.country,"country1","country1"),"Select")</td>                   </tr>               <tr>                   <td>                     State:<br />                       @Html.DropDownListFor(x=>x.State,new SelectList(ViewBag.state,"state1","State1"),"Select")                                          </td>                   <td>District:@Html.DropDownListFor(x
=>x.District, new SelectList(ViewBag.district,"district1","district1"),"Select")</td>                   </tr>                              </table>                &nbsp; <input type="submit" value="Submit" />               </fieldset>      
}   
</div></body></html> 
```

\

View page Look like

\

![How to pass multiple dropdown list values from view to controller and saving into a database?](https://www.mindstick.com/mindstickforums/741b3b1d-4c0b-4581-80cb-9a666552ef19/images/13230d13-69c8-4262-85c8-a51cff2cd88d.png)\

\

\

\


---

Original Source: https://www.mindstick.com/forum/34288/how-to-pass-multiple-dropdown-list-values-from-view-to-controller-and-saving-into-a-database

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
