0
I have a select that is being 'populated' as follows in my ASP.NET application:
<select id="id_select" class="form-control">
@foreach (var x in listay)
{
<option value = "@x.nome"> @x.nome </option>
}
</select>
This way, I’m able to display the names I have in "listay".
However, my application should display on the screen all data relating to the name that the user clicks on a select option. Like, for example: By clicking on an option - the name "John", for example - other data that is associated with João
should be displayed just below on the screen, such as last name, age, date of birth, etc. I have all this data in my "listay" - and I can access it using "@x.last name", "@x.age", "@x.dataNascimento" - but I don’t know how to associate this data to the option that the user click on select.
Please, could someone guide me how to proceed to resolve this impasse? I thank you for your attention.
Hello! Thank you for the answer! Could you help me with a question? With regard to "Code to display John fields", how could I 'call' the data - like x.last name, x.age, x.dataNascimento - in the Javascript function, if they are inside the 'foreach' that populates the select? Thank you for your attention.
– Riccarsan
Riccarsan, there are some ways to do this. The first is to use the controller to fetch the data from the specific user you want and then use a Viewbag or Viewdata to pass the data to the View. The second is to access it directly on the list, with Inglo. You could create a global variable, inside @{} at the beginning of the page, something like: var dadsLista = listay.Where(x => x.id == idUsuarioQueVoceQuer); Then just access in the code: @dadsList.last name and so on. But I already assume that the most common is with Viewbag. In case I helped you, could you mark the question as solved? Abç
– Jaderson