5
我在这里错过了什么?将mvc3中的下拉列表绑定到字典?
视图模型:
public class ViewModel
{
public IDictionary<int, string> Entities { get; set; }
public int EntityId { get; set; }
}
控制器:
public override ActionResult Create(string id)
{
ViewModel = new ViewModel();
IEnumerable<Entity> theEntities = (IEnumerable <Entity>)db.GetEntities();
model.Entities= theEntities.ToDictionary(x => x.Id, x => x.Name);
return View(model);
}
查看:
<div class="editor-field">@Html.DropDownListFor(model => model.EntityId,
new SelectList(Model.Entities, "Id", "Name"))</div>
</div>
错误:
DataBinding: 'System.Collections.Generic.KeyValuePair....does not contain a property with the name 'Id'
喜,thx回复,但我的身份证不是重叠群。从我希望构建的列表中返回的结果选择列表并存储选定的ID如下:[2] =“Joes ent”,[9] =“Johns ent”...等等,所以这就是为什么我希望捕获与dstabase模型中关联的id相对应的选定id。 – Mariah 2012-04-02 21:22:57
然后改变你的看法到'
真棒,thx !!!!!!! – Mariah 2012-04-02 21:40:14