Populating List in DropDownListhttp://forums.asp.net/t/1701941.aspx/1?Populating+List+in+DropDownListWed, 20 Jul 2011 16:08:13 -040017019414516474http://forums.asp.net/p/1701941/4516474.aspx/1?Populating+List+in+DropDownListPopulating List in DropDownList <p>Hi,</p> <p>I trying to populate data into DDL using List. is it possible?</p> <p>Following is my code :</p> <p><strong>Category.cs</strong></p> <pre class="prettyprint">public class Categories { int id; string category; public Categories() {} public Categories(int i, string cat) { this.id = i; this.category = cat; } public int Id { get; set; } public string Category { get; set; } }</pre> <p><strong>HomeController/Create</strong></p> <pre class="prettyprint">public ActionResult Create() { IList&lt;Categories&gt; c = new List&lt;Categories&gt;(); c.Add(new Categories(1, "Cricket")); c.Add(new Categories(2, "Carom")); c.Add(new Categories(3, "Football")); ViewData["Category"] = new SelectList(c.ToList()); // I want display category here. I can not access id and category through List return View(); }</pre> <p>I am able to achieve this using Ms Entity Framework.</p> <p></p> <p>Thanks</p> <p>Vish</p> 2011-07-20T14:26:35-04:004516491http://forums.asp.net/p/1701941/4516491.aspx/1?Re+Populating+List+in+DropDownListRe: Populating List in DropDownList <p>into DLL you can use list but not selectedlistItem, you need to add SYstem.Web.MVC tod o that</p> 2011-07-20T14:37:35-04:004516645http://forums.asp.net/p/1701941/4516645.aspx/1?Re+Populating+List+in+DropDownListRe: Populating List in DropDownList <p>Use a DropDownList(DropDownListFor) for handling a list instead of a single value. The you can bind it to a list.</p> 2011-07-20T16:08:13-04:00