Asp.Net MVC3 - How create Dynamic DropDownList

Posted by Bibo on Stack Overflow See other posts from Stack Overflow or by Bibo
Published on 2011-02-19T07:22:51Z Indexed on 2011/02/19 7:25 UTC
Read the original article Hit count: 197

Filed under:
|

I found many articles on this but still I don´t know how exactly to do this. I am trying to create my own blog engine, I have View for create article (I am using EF and Code first) and now I must fill number of category in which article should be add but I want to change it to dropdownlist with names of categories. My model looks this:

public class Article
{
    public int ArticleID { get; set; }
    [Required]
    public string Title { get; set; }
    [Required]
    public int CategoryID { get; set; }
    public DateTime Date { get; set; }
    [Required()]
    [DataType(DataType.MultilineText)]
    [AllowHtml]
    public string Text { get; set; }
    public virtual Category Category { get; set; }
    public IEnumerable<SelectListItem> Categories { get; set; }
    public virtual ICollection<Comment> Comments { get; set; }
}
public class Category
{
    public int CategoryID { get; set; }
    [Required]
    public string Name { get; set; }
    public virtual ICollection<Article> Articles { get; set; }

}

I know I must use Enum (or I think) but I am not exactly sure how. I don´t know which tutorial from that I found is best for me.

© Stack Overflow or respective owner

Related posts about asp.net-mvc-3

Related posts about dropdownlist