0
我想一个dropdownlistfor
绑定到来自数据库MVC从数据库中获得
在模型
public class Actor
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
...
// I have a database table called genre
[ForeignKey("Genre")]
public virtual IEnumerable<Genre> Genres { get; set; }
}
在控制器
// GET: Actors/Create
public ActionResult Create()
{
Actor actor = new Actor();
actor.Genres = new // Believe I need to do something here...
return View(actor);
}
在列表中虚拟的IEnumerable查看
<div class="form-group">
@Html.LabelFor(model => model.Genres, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
<div class="dropdown">
@Html.DropDownListFor(M => M.Genre, new SelectList(Model.Genres, "Value", "Text"))
</div>
</div>
</div>
我需要做什么?
感谢