Step1
We need to put this code in the controller i.e
IndexController
ViewBag.Categories = db.Categories.ToList();
Where db is a object of a database connection and categories is the name of the
table
Step2
We also need to put the code in the cshtml
page i.e IndexCshtml.
@Html.DropDownListFor(model => model.CategoryId, new
SelectList(ViewBag.Categories, "CategoryId", "CategoryName"), "Select a
Category")


Lalit RaghuvanshiPosted Jan 17, 2015, 10:52 PM EST
After searching lots of blogs and website , i found the clear step by step and easiest solution to bind dropdownlist from sql database on :Dynamically bind Asp.Net MVC Dropdownlist from Sql Server Database using entity frameworkhttp://www.webcodeexpert.com/2015/01/how-to-dynamically-bind-aspnet-mvc.html
Łukasz KordowskiPosted Aug 25, 2014, 2:10 AM EDT
hey thanks. but have one issue. it sends null or 0 instead of chosen index to model. any idea?
pavan kumarPosted Aug 7, 2014, 8:43 PM EDT
Thanku sir i am new to mvc