0
下午所有。将下拉列表设置为MVC中的特定值3剃须刀
我有一个下拉列表,我视图
<div class="editor-label">
@Html.LabelFor(model => model.SiteTypeId, "SiteType")
</div>
<div class="editor-field">
@Html.DropDownList("SiteTypeId", (IEnumerable<SelectListItem>) ViewBag.SiteTypeId)
@Html.ValidationMessageFor(model => model.SiteTypeId)
</div>
随着模式看起来像这样:
public class SiteType
{
[Key]
public int SiteTypeId { get; set; }
public string SiteTypeName { get; set; }
}
目前,有刚刚在下拉菜单的两个项目:
1 (value) - Foo (item)
2 (value) - Bar (item)
通过控制器一拉出现:
public ActionResult Details(Guid id)
{
var model = Model(id);
ViewBag.SiteTypeId = new SelectList(db.SiteTypes, "SiteTypeId", "SiteTypeName");
return View(model.Details);
}
用户将相应地更新这一点,它会被存储在数据库中。
我可以从数据库中获得下拉列表的值没有问题,但我怎么能有效地将这个值绑定到列表?
人,我觉得简单问这样的:'(
任何帮助总是赞赏
哦,我的话......回家的时间我认为达林! –