V
V
VanilaSpirit2020-06-30 15:48:22
ASP.NET
VanilaSpirit, 2020-06-30 15:48:22

How to display a list from a database in ASP NET Core?

There is a Player class in which
Id, Name, Age, Gender, Team

In Team:
Id, Name

On the add page there is a Player model (for the form)
But you also need to display it in all Team values ​​​​(to select accordingly)

foreach (var item in Model.Team)
{
                    <option value="@item.Id">@item.Name</option>
}


It is impossible to declare the second model on the page, as I understand it.
Is it necessary to create a general model for Player - Team, or can it be displayed without it?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Roman, 2020-07-01
@yarosroman

ViewData or ViewBag to help you, just in case you pass a lot of data to the model

E
Egor, 2020-07-02
@exorka

The model can be any class for your needs, you can encapsulate any necessary subclasses in your model.

B
Bal4ss, 2020-07-02
@Bal4ss

https://metanit.com/sharp/aspnet5/8.1.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question