friend you can do in two ways, are the ones I know and apply in the solutions here:
1° option:
<label>Categoria</label>
<select asp-for="Establishment.Id_Category" asp-items="@(new SelectList(Model.Category,"idCategory","CategoryName"))" id="category" class="form-control" required>
<option selected disabled>Categoria</option>
</select>
2° option
<label for="categoria">Categoria*</label>
<select id="categoria" name="categoria" class="form-control">
<option selected>Selecione uma Categoria</option>
@foreach (var C in ViewBag.ListaCategoria)
{
<option value="@(C.idCategoria)">@(C.nomeCategoria)</option>
}
</select>
both examples provide a list of categories for the client, and when the user selects a category, what goes to the server is the ID of that category, the ID would be a category identifier in the database to make the relationship between tables and such...
in your case what matters to you is the value, is in it that you put what can identify all the data, if you are going to do a search in the bd, can be an ID for example...
but what is the criterion? you need to know what you want, the first?
Model.FirstOrDefault()
, the client with Id 3?Model.FirstOrDefault(c => c.Id == 3)
.... are examples, give more details– Ricardo Pontual
Would not be
Model.Contatos.FirtOrDefault
? I want to get the first item on the list– Rafael Passos
yes that’s right, I put only examples. If it’s just the first one it already solves, or if I’m sure the list is filled,
First()
– Ricardo Pontual