Skip to main content
spellings
Source Link
Henk Holterman
  • 275.5k
  • 33
  • 353
  • 540

Is there a way to scaffold a model that has child classes inside?

I was following a blazor tutorial and there is this step where it can create a CRUD with just the model of a class. In the tutorial they only show it with a very simple class. I wanted to know if it is possible to do the same but with a class that ashas child class inside.

public class Match
{
    public int Id { get; set; }
    public DateTime MatchTimestamp { get; set; }
    public Player? Player1 { get; set; }
    public Player? Player2 { get; set; }
    public int Player1Score { get; set; }
    public int Player2Score { get; set; }
}

When I tried to scaffoledscaffold this class, it did not completlycompletely generate the html. 
Here an example in the Index.razor :

<QuickGrid Class="table" Items="context.Match">
    <PropertyColumn Property="match => match.MatchTimestamp" />
    <PropertyColumn Property="match => match.Player1Score" />
    <PropertyColumn Property="match => match.Player2Score" />

    <TemplateColumn Context="match">
        <a href="@($"matches/edit?id={match.Id}")">Edit</a> |
        <a href="@($"matches/details?id={match.Id}")">Details</a> |
        <a href="@($"matches/delete?id={match.Id}")">Delete</a>
    </TemplateColumn>
</QuickGrid>

It did not generate the code to display Player1 or Player2. Is there a way to do it ?

Is there a way to scaffold a model that child classes inside?

I was following a blazor tutorial and there is this step where it can create a CRUD with just the model of a class. In the tutorial they only show it with a very simple class. I wanted to know if it is possible to do the same but with a class that as child class inside.

public class Match
{
    public int Id { get; set; }
    public DateTime MatchTimestamp { get; set; }
    public Player? Player1 { get; set; }
    public Player? Player2 { get; set; }
    public int Player1Score { get; set; }
    public int Player2Score { get; set; }
}

When I tried to scaffoled this class, it did not completly generate the html. Here an example in the Index.razor :

<QuickGrid Class="table" Items="context.Match">
    <PropertyColumn Property="match => match.MatchTimestamp" />
    <PropertyColumn Property="match => match.Player1Score" />
    <PropertyColumn Property="match => match.Player2Score" />

    <TemplateColumn Context="match">
        <a href="@($"matches/edit?id={match.Id}")">Edit</a> |
        <a href="@($"matches/details?id={match.Id}")">Details</a> |
        <a href="@($"matches/delete?id={match.Id}")">Delete</a>
    </TemplateColumn>
</QuickGrid>

It did not generate the code to display Player1 or Player2. Is there a way to do it ?

Is there a way to scaffold a model that has child classes inside?

I was following a blazor tutorial and there is this step where it can create a CRUD with just the model of a class. In the tutorial they only show it with a very simple class. I wanted to know if it is possible to do the same but with a class that has child class inside.

public class Match
{
    public int Id { get; set; }
    public DateTime MatchTimestamp { get; set; }
    public Player? Player1 { get; set; }
    public Player? Player2 { get; set; }
    public int Player1Score { get; set; }
    public int Player2Score { get; set; }
}

When I tried to scaffold this class, it did not completely generate the html. 
Here an example in the Index.razor :

<QuickGrid Class="table" Items="context.Match">
    <PropertyColumn Property="match => match.MatchTimestamp" />
    <PropertyColumn Property="match => match.Player1Score" />
    <PropertyColumn Property="match => match.Player2Score" />

    <TemplateColumn Context="match">
        <a href="@($"matches/edit?id={match.Id}")">Edit</a> |
        <a href="@($"matches/details?id={match.Id}")">Details</a> |
        <a href="@($"matches/delete?id={match.Id}")">Delete</a>
    </TemplateColumn>
</QuickGrid>

It did not generate the code to display Player1 or Player2. Is there a way to do it ?

added 3 characters in body
Source Link
Christophe
  • 75.1k
  • 7
  • 87
  • 182

I was following a blazor tutorial and there is this step where it can create a CRUD with just the model of a class. [https://learn.microsoft.com/en-us/aspnet/core/blazor/tutorials/movie-database-app/part-2?view=aspnetcore-9.0&pivots=vsc] InIn the tutorialtutorial they only show it with a very simple class. I I wanted to know if it is possible to do the same but with a class that as child class inside.

public class Match
{
    public int Id { get; set; }
    public DateTime MatchTimestamp { get; set; }
    public Player? Player1 { get; set; }
    public Player? Player2 { get; set; }
    public int Player1Score { get; set; }
    public int Player2Score { get; set; }
}

When I tried to scaffoled this class, it did not completly generate the html. Here an example in the Index.razor Index.razor :

<QuickGrid Class="table" Items="context.Match">
    <PropertyColumn Property="match => match.MatchTimestamp" />
    <PropertyColumn Property="match => match.Player1Score" />
    <PropertyColumn Property="match => match.Player2Score" />

    <TemplateColumn Context="match">
        <a href="@($"matches/edit?id={match.Id}")">Edit</a> |
        <a href="@($"matches/details?id={match.Id}")">Details</a> |
        <a href="@($"matches/delete?id={match.Id}")">Delete</a>
    </TemplateColumn>
</QuickGrid>

It did not generate the code to display Player1Player1 or Player2Player2. Is there a way to do it ? Thanks.

I was following a blazor tutorial and there is this step where it can create a CRUD with just the model of a class. [https://learn.microsoft.com/en-us/aspnet/core/blazor/tutorials/movie-database-app/part-2?view=aspnetcore-9.0&pivots=vsc] In the tutorial they only show it with a very simple class. I wanted to know if it is possible to do the same but with a class that as child class inside.

public class Match
{
    public int Id { get; set; }
    public DateTime MatchTimestamp { get; set; }
    public Player? Player1 { get; set; }
    public Player? Player2 { get; set; }
    public int Player1Score { get; set; }
    public int Player2Score { get; set; }
}

When I tried to scaffoled this class, it did not completly generate the html. Here an example in the Index.razor :

<QuickGrid Class="table" Items="context.Match">
    <PropertyColumn Property="match => match.MatchTimestamp" />
    <PropertyColumn Property="match => match.Player1Score" />
    <PropertyColumn Property="match => match.Player2Score" />

    <TemplateColumn Context="match">
        <a href="@($"matches/edit?id={match.Id}")">Edit</a> |
        <a href="@($"matches/details?id={match.Id}")">Details</a> |
        <a href="@($"matches/delete?id={match.Id}")">Delete</a>
    </TemplateColumn>
</QuickGrid>

It did not generate the code to display Player1 or Player2. Is there a way to do it ? Thanks.

I was following a blazor tutorial and there is this step where it can create a CRUD with just the model of a class. In the tutorial they only show it with a very simple class. I wanted to know if it is possible to do the same but with a class that as child class inside.

public class Match
{
    public int Id { get; set; }
    public DateTime MatchTimestamp { get; set; }
    public Player? Player1 { get; set; }
    public Player? Player2 { get; set; }
    public int Player1Score { get; set; }
    public int Player2Score { get; set; }
}

When I tried to scaffoled this class, it did not completly generate the html. Here an example in the Index.razor :

<QuickGrid Class="table" Items="context.Match">
    <PropertyColumn Property="match => match.MatchTimestamp" />
    <PropertyColumn Property="match => match.Player1Score" />
    <PropertyColumn Property="match => match.Player2Score" />

    <TemplateColumn Context="match">
        <a href="@($"matches/edit?id={match.Id}")">Edit</a> |
        <a href="@($"matches/details?id={match.Id}")">Details</a> |
        <a href="@($"matches/delete?id={match.Id}")">Delete</a>
    </TemplateColumn>
</QuickGrid>

It did not generate the code to display Player1 or Player2. Is there a way to do it ?

Source Link

Is there a way to scaffold a model that child classes inside?

I was following a blazor tutorial and there is this step where it can create a CRUD with just the model of a class. [https://learn.microsoft.com/en-us/aspnet/core/blazor/tutorials/movie-database-app/part-2?view=aspnetcore-9.0&pivots=vsc] In the tutorial they only show it with a very simple class. I wanted to know if it is possible to do the same but with a class that as child class inside.

public class Match
{
    public int Id { get; set; }
    public DateTime MatchTimestamp { get; set; }
    public Player? Player1 { get; set; }
    public Player? Player2 { get; set; }
    public int Player1Score { get; set; }
    public int Player2Score { get; set; }
}

When I tried to scaffoled this class, it did not completly generate the html. Here an example in the Index.razor :

<QuickGrid Class="table" Items="context.Match">
    <PropertyColumn Property="match => match.MatchTimestamp" />
    <PropertyColumn Property="match => match.Player1Score" />
    <PropertyColumn Property="match => match.Player2Score" />

    <TemplateColumn Context="match">
        <a href="@($"matches/edit?id={match.Id}")">Edit</a> |
        <a href="@($"matches/details?id={match.Id}")">Details</a> |
        <a href="@($"matches/delete?id={match.Id}")">Delete</a>
    </TemplateColumn>
</QuickGrid>

It did not generate the code to display Player1 or Player2. Is there a way to do it ? Thanks.