---
title: "Bind Dropdown in MVC"  
description: "In Model    1. Firstly create model class named Course and create property  using System;  using System.Collections.Generic;  using System.Linq;  usin"  
author: "Ranjeet Kumar"  
published: 2013-10-10  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/607/bind-dropdown-in-mvc  
category: "asp.net mvc"  
tags: ["asp.net mvc"]  
reading_time: 2 minutes  

---

# Bind Dropdown in MVC

In Model\
\
1. Firstly create [model class](https://www.mindstick.com/forum/160267/what-is-the-role-of-the-range-data-annotation-and-when-to-use-it-in-a-model-class) named Course and create property\
using System;\
using System.Collections.Generic;\
using System.Linq;\
using System.Web;\
using System.ComponentModel.DataAnnotations;\
using System.Web.Mvc;\
\
[namespace](https://www.mindstick.com/articles/12552/namespace) StudentRecord.Models\
{\
public class Course\
{\
\
public int CourseId { get; set; }\
\
[Display(Name = "Course Name")]\
[Required(ErrorMessage = "Enter Course Name")]\
public string CourseName { get; set; }\
}\
}\
\
2. Then create another model class [named as](https://answers.mindstick.com/qa/62213/name-the-cricketer-who-was-named-as-the-player-of-the-tournament-in-cricket-world-cup-2019) u wish. Here we use [connection](https://www.mindstick.com/articles/13012/what-makes-ethernet-connection-better-than-wifi) string and [stored procedure](https://www.mindstick.com/articles/803/using-stored-procedure-in-asp-dot-net).but i am using dll class here for connectivity.\
\
public class DbConnectivity\
{\
private static string Config = System.Configuration.ConfigurationManager.ConnectionStrings["strCon"].ConnectionString;\
\
public List<Course> DropCourse()\
{\
[Database](https://www.mindstick.com/articles/12226/use-of-database-in-sencha-extjs-and-insert-record-from-user-form-using-ajax) db = new SqlDatabase(Config);\
DbCommand dbCommand = db.GetStoredProcCommand("DISPLAYCOURSE");\
List<Course> list = new List<Course>();\
using (IDataReader [dataReader](https://www.mindstick.com/forum/160514/how-to-use-datareader-in-asp-dot-net-c-sharp) = db.ExecuteReader(dbCommand))\
{\
while (dataReader.Read())\
{\
Course obj = new Course();\
if (dataReader["Course"] != DBNull.Value)\
{\
if (dataReader["Course"] != DBNull.Value) { obj.CourseId = (int)dataReader["Course"]; }\
if (dataReader["COURSENAME"] != DBNull.Value) { obj.CourseName = (string)dataReader["COURSENAME"]; }\
list.Add(obj);\
}\
}\
return list;\
}\
}\
}\
3.\
In [Controller](https://www.mindstick.com/blog/273/passing-values-from-controller-to-view-in-asp-dot-net-mvc)\
public [ActionResult](https://www.mindstick.com/forum/33961/what-is-the-difference-between-actionresult-and-viewresult) Drop()\
{\
DbConnectivity dbconnection = new DbConnectivity();\
List<Course> pcontent = new List<Course>();\
{\
//Get all page content from TblHome table\
pcontent = dbconnection.DisplayCourse();\
\
};\
List<SelectListItem> cityList = new List<SelectListItem>();\
//List<string> items = new List<string>();\
foreach (var item in pcontent)\
{\
cityList.Add(new SelectListItem\
{\
Text = item.CourseName,\
Value = item.CourseId.ToString()\
});\
}\
\
ViewBag.CityList = cityList;\
return View();\
\
\
//return View(pcontent);\
}\
\
\
In public ActionResult Drop()\
{\
DbConnectivity dbconnection = new DbConnectivity();\
List<Course> pcontent = new List<Course>();\
{\
//Get all page content from TblHome table\
pcontent = dbconnection.DisplayCourse();\
\
};\
List<SelectListItem> cityList = new List<SelectListItem>();\
//List<string> items = new List<string>();\
foreach (var item in pcontent)\
{\
cityList.Add(new SelectListItem\
{\
Text = item.CourseName,\
Value = item.CourseId.ToString()\
});\
}\
\
ViewBag.CityList = cityList;\
return View();\
\
\
//return View(pcontent);\
}\
\
4.\
In View\
\
@model StudentRecord.Models.Course\
\
@{\
ViewBag.Title = "Drop";\
Layout = "~/Views/Shared/_Layout.cshtml";\
}\
\
<h2>Drop</h2>\
\
\
<fieldset>\
<legend>Course</legend>\
\
<div class="display-label">CourseName</div>\
<div class="display-field">\
@Html.DropDownList("CityName", (IEnumerable<SelectListItem>)ViewBag.cityList)\
</div>\
</fieldset>\
@using ([Html.BeginForm](https://www.mindstick.com/forum/1944/html-beginform-post-going-to-httpget-action-rather-than-httppost-in-ie-fine-in-chrome-and-firefox)())\
\
{ \
<p>\
<input type="Submit" value="Submit" />\
\
</p>\
\
}

---

Original Source: https://www.mindstick.com/blog/607/bind-dropdown-in-mvc

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
