2016-03-25 10 views
0
<!DOCTYPE html> 

<html> 



@{ 
PRO1.Modelo.DBMundo Datos = new PRO1.Modelo.DBMundo(); 
List<PRO1.Modelo.Country> countrylist = Datos.Country.Distinct().ToList(); 
List<PRO1.Modelo.City> citylist = Datos.City.Distinct().ToList(); 
} 


<head> 
<meta name="viewport" content="width=device-width" /> 
<title>Paises</title> 
</head> 
<body> 
<p>Seleciona las opciones</p> 
<p>Codigo de pais</p> 
<form name="formula1" method="post" action=""> 


    <select name="selcodpais"> 
     <optgroup label="prueba"> 
      @{ 

       foreach (PRO1.Modelo.Country registro in countrylist) 
       { 
        <option value="a">@registro.Continent</option> 
       } 

      } 
     </optgroup> 

    </select> 
    <input type="submit" value="Buscar" /> 



    </form> 



    </body> 
    </html> 

Also, was im Versuch ist es, alle Elemente auf dem Auswahl-Formular die Tabelle Formular anzuzeigen, aber ich halte theese Duplikate Geting sogar .Distinct mit(), i Ich möchte nur ein Mal pro Stück angezeigt werden, vielleicht mit Gruppe von, aber ich weiß immer noch nicht, wie es zu tun, da ich ein Neuling bin, wenn Sie auch etwas Ahnung oder Informationen darüber haben, ich werde es wirklich schätzen DankDistinct Elemente der Abfrage auf einer Liste „Entity Framework Razor“

Antwort

1

Muss es sagen, was es unterscheidet - sonst geht es durch Objektreferenz. Unter der Annahme eines Landes hat es eine Eigenschaft Name ...

List<PRO1.Modelo.Country> countrylist = Datos.Country.Distinct(c => c.Name).ToList(); 
+0

thx im werde versuchen jetzt –

+0

srry mein schlecht, tat es work'd –

Verwandte Themen