Here is what I have in my controller:
Category x = new Category(1, "one", 0);
Category y = new Category(2, "two", 1);
List<Category> cat = new List<Category>();
cat.Add(x);
cat.Add(y);
ViewData["categories"] = new SelectList(cat, "id", "name");
My view:
<%= Html.DropDownList("categories")%>
But, my class Category has a property named idParent. I want the dropdown to be field with values like this: ParentName -> CategoryName
public class Category {int idParent, string name, int id}
I tried like this:
ViewData["categories"] = new SelectList(cat, "id", "idParent" + "name");
but it's not working. Do you have any idea?