Do you know how i could use the loop "while" and "foreach" to display the results For my code :
Control.cs :
IEnumerable<Acces> all_id = acces_Repository.FindAll("where email = '" + id_ + "'");
ViewBag.Acceslist = all_id;
ViewBag.Liste = listeRepository.FindAll(" order by id ASC ");
Function.cs :
public IEnumerable<Acces> FindAll(string where = "")
{
try {
using (IDbConnection dbConnection = Connection)
{
dbConnection.Open();
return dbConnection.Query<Acces>("SELECT * FROM access "+where);
}
}
catch (Exception ex)
{
ex.ToString();
return null;
}
}
I would like for its result in acces.cshtml:
<select class=" chosen-select form-control form-control-sm" name="id" value="" multiple="multiple">
@foreach (var item in ViewBag.Liste)
{
@foreach (var item12 in ViewBag.Acces_liste)
{
@if (item.Id == item12.Id)
{
<option value="@item12.Id" checked selected="selected">@item12.Id</option>
} else {
<option value="@item.Id">@item.Id</option>
}
}
}
</select>
I have two functions which do not return the same results but come from the same database. In order to display all the results but selecting the correct ones. To get this result: Result