5
私はここで何が欠けていますか?mvc3のドロップダウンリストを辞書にバインドしますか?
のViewModel:
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'
こんにちは:あなたは本当に辞書<>を使用する必要がある場合、
をOR、あなたのビューを変更します、返信のためのthxしかし私のidはcontigではない。選択リストを作成して選択したIDを保存するリストからの結果は、次のようになります。[2] = "Joes ent"、[9] = "Johns ent" ...など。 dstabaseモデルの関連IDに対応する選択されたIDを取得します。 – Mariah
次に、ビューを「
「Awesome、thx !!!!!!!」に変更します。 – Mariah