2017-05-19 3 views
-2

Ich habe eine Dropdown-Liste für Standorte, die derzeit nach Land in einem ASP MVC-Programm gruppiert ist.
die Drop der Standorte Liste wird mit der folgenden Zeile in meinem Ansichtsmodell bevölkert:ASP.NET MVC: DropDownList gruppiert nach Name nicht ID

ViewBag.Locations = new MultiSelectList(db.tblLocations, "LocationID", "LocationName", "CountryID"); 

Derzeit ist die Dropdown-Liste zeigt die Länder als ihre IDs nicht mit Namen.

z.B.
Lage
Lage
Lage
Lage
Lage

Gibt es eine Möglichkeit die Länder anzuzeigen, in dem Dropdown haben unten nach Namen statt ID?

Jede Hilfe wäre willkommen.
Danke.

EDIT:
tblLocations:
LocationID
Location
countryid

tblCountries
countryid
Country

Antwort

0

können Sie es wie folgt tun:

ViewBag.Locations = new MultiSelectList(db.tblLocations, "LocationID", "LocationName", "tblCountries.CountryName"); 

aber Sie müssen die tblCountries in tblLocations

+0

Das funktionierte aufzunehmen. Vielen Dank. – AmateurDev