Asp.net mvc 4 Dropdownlist和MVC4实体框架
这是我的模型课 公开课问题Asp.net mvc 4 Dropdownlist和MVC4实体框架,asp.net-mvc-4,Asp.net Mvc 4,这是我的模型课 公开课问题 { [Key] public int Id { get; set; } public int PollId { get; set; } public string Title { get; set; } public string Type { get; set; } public string Body { get; set; } public string Options { get; set;
{
[Key]
public int Id { get; set; }
public int PollId { get; set; }
public string Title { get; set; }
public string Type { get; set; }
public string Body { get; set; }
public string Options { get; set; }
public int Priority { get; set; }
public bool IsActive { get; set; }
public DateTime CreatedOn { get; set; }
public DateTime ModifiedOn { get; set; }
public List<Vote> Answers { get; set; }
}
最后是我的看法
@Html.DropDownList("MyOption","---Select---")
我该怎么办?请在您的控制器中帮助我
ViewBag.MyOption = new SelectListItem() { Text = "Options" , Value = "Options" };
var optionslist = options.Split(',').ToList(); //split comma seperated into list
ViewBag.MyOption = optionslist // Your List of an options
在你看来
@Html.DropDownList("Select Option",new SelectList(ViewBag.MyOption))
存储逗号分隔的字符串是数据库非规范化的一种形式。您应该考虑将您的选项拆分为另一个表,并将外键返回到此表(一对多)。即使您根据给定的值进行拆分,该值是否与文本相同?