當我使用從實體框架和設計器自動創建控制器/模型/視圖時,我得到一個相當乾淨的編輯表單。 1對1關係中的一個會創建一個下拉列表,向用戶顯示來自特定列的值,但我希望它能夠使用另一列/屬性。覆蓋下拉列表(MVC3,實體框架)的視圖列
這是如何完成的?
(僅供參考,我不希望在MVVM類,以及如何在一個視圖模型隔離這一點。我沒有學習和重新創建視圖模型類此應用程序的帶寬。)
<div class="editor-label">
@Html.LabelFor(model => model.Domain, "Domain1")
</div>
<div class="editor-field">
@Html.DropDownList("Domain", String.Empty))
@Html.ValidationMessageFor(model => model.Domain)
</div>
控制器:
public ActionResult Edit(int id)
{
ClientJob clientjob = db.ClientJobs.Find(id);
ViewBag.ClientId = new SelectList(db.Clients, "Id", "ClientName", clientjob.ClientId);
ViewBag.CurrencyType = new SelectList(db.CurrencyTypes, "Id", "TypeName", clientjob.CurrencyType);
ViewBag.Domain = new SelectList(db.Domains, "Id", "DomainName", clientjob.Domain);
ViewBag.JobType = new SelectList(db.JobTypes, "Id", "JobTypeName", clientjob.JobType);
ViewBag.DatabaseServer = new SelectList(db.Servers, "Id", "ServerName", clientjob.DatabaseServer);
ViewBag.ProcessingServer = new SelectList(db.Servers, "Id", "ServerName", clientjob.ProcessingServer);
ViewBag.QueryServer = new SelectList(db.Servers, "Id", "ServerName", clientjob.QueryServer);
return View(clientjob);
}
我想我只是回答了我的問題...... LOL – 2011-05-20 22:49:40
看到我的答案,或者我的編輯 – 2011-05-20 22:53:24