Reputation: 1
<!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>
So what im trying is to display all the items form the table on the select form, but i keep geting theese duplicates even using .Distinct(), i only want to be displayed one time per item, maybe using group by but i still dont know how to do it since im a newbie if u also have some clue or information about it i will really apreciate it Thanks by the way
Upvotes: 0
Views: 293
Reputation: 16464
Need to tell it what makes it distinct -- otherwise it goes by object reference. Assuming a country has a Name property...
List<PRO1.Modelo.Country> countrylist = Datos.Country.Distinct(c => c.Name).ToList();
Upvotes: 1