I want to display the names of people who don't have adepartamento
The data is:
+----+---------+----------------+ +----+--------------------+
| id | Nombre | idDepartamento | | id | NombreDepartamento |
+----+---------+----------------+ +----+--------------------+
| 44 | Daniel | 1 | | 1 | Desarrollo |
+----+---------+----------------+ +----+--------------------+
| 45 | Manuel | 0 | | 2 | Contabilidad |
+----+---------+----------------+ +----+--------------------+
| 47 | Juan | 0 |
+----+---------+----------------+
| 49 | Alfonso | 0 |
+----+---------+----------------+
I want to show them in a select
html using razor in asp.net -mvc-5
I have the following code:
<select class="form-control" name="UsuarioSelect" multiple>
@{foreach (var departamento in Model.Departamentos)
{
<optgroup label="@departamento.Departamento"></optgroup>
foreach (var empleado in Model.Empleados)
{
if (empleado.IdDepartamento == departamento.id)
{
<option value="@empleado.id">@empleado.Nombre</option>
}
}
}}
</select>
But I have no idea how to show the users who don't have a department.
What do I need to add in my code to make them show up?
What I want to achieve is something like this:
$('select').select2({
width: '50%'
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js"></script>
<select class="Select2" multiple>
<optgroup label='Desarrollo'></optgroup>
<option value='44'>Daniel</option>
<optgroup label='Contabilidad'></optgroup>
<optgroup label='Sin Departaento'></optgroup>
<option value='45'>Juan</option>
<option value='47'>Manuel</option>
<option value='49'>Alfonso</option>
</select>
Try the following using
Linq
in your in your razor: