When I use the auto creation of controllers/models/views from entity framework and designer I get a pretty clean edit form. One of the 1 to 1 relationships creates a dropdownlist that presents the user with values from a specific column but I want it to user another column/property.
How is this done?
(FYI, I’m not looking for a class in MVVM and how to isolate this in a view model. I don’t have the bandwidth to learn and recreate this application with view model classes.)
<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>
controller:
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);
}
The auto created code just created select lists:
I just needed to change the column name in the SelectList: