I trying to populate data into DDL using List. is it possible?
Following is my code :
Category.cs
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; }
}
HomeController/Create
public ActionResult Create()
{
IList<Categories> c = new List<Categories>();
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();
}
I am able to achieve this using Ms Entity Framework.
visharaddhav...
Member
95 Points
91 Posts
Populating List in DropDownList
Jul 20, 2011 02:26 PM|LINK
Hi,
I trying to populate data into DDL using List. is it possible?
Following is my code :
Category.cs
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; } }HomeController/Create
public ActionResult Create() { IList<Categories> c = new List<Categories>(); 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(); }I am able to achieve this using Ms Entity Framework.
Thanks
Vish
Live every moment of life, thoroughly