I have created a component with a DataGrid, following the example:
Master and detail Blazor DataGrid (radzen.com, which does not render correctly. The values in the data grid columns do not list the property value, but the C# Type of the Model:
2020-11-23_19-13-23|690x116
Any suggestions would be greatly appreciated.
This is the Razor component:
@page "/programs" @using CompuTax.Client.Pages.Common @using CompuTax.Shared.Models.Common <AuthorizeView> <Authorized> @if (Programs == null) { <Loading></Loading> } else { <div class="row"> <div class="col-md-6"> <RadzenGrid Count="@ProgramCount" Data="@Programs" TItem="TaxProgram" Value="@Program" RowSelect="@(args => Program = args)" ColumnWidth="200px" AllowFiltering="true" AllowPaging="true" PageSize="5" AllowSorting="true"> <Columns> <RadzenGridColumn Width="100px" TItem="TaxProgram" Property="Program" Title="Tax Program" /> <RadzenGridColumn Width="100px" TItem="TaxProgram" Property="Module" Title="Module" /> </Columns> </RadzenGrid> </div> <div class="col-md-6"> <RadzenCard Style="margin-bottom:20px"> Tax Program: <b>@Program.Program</b> </RadzenCard> <RadzenGrid Count="@Program.TaxYears.Count()" Data="@Program.TaxYears" TItem="TaxYear" ColumnWidth="100px" AllowFiltering="true" AllowPaging="true" AllowSorting="true"> <Columns> <RadzenGridColumn Width="100px" TItem="TaxYear" Property="Year" Title="Tax Year" Type="integer" /> </Columns> </RadzenGrid> </div> </div> } </Authorized> <Authorizing> <Loading></Loading> </Authorizing> </AuthorizeView>
This is the Code Behind:
public partial class TaxPrograms { [Inject] private HttpClient Http { get; set; } protected int ProgramCount; protected int YearCount; protected TaxProgram Program; protected IEnumerable<TaxProgram> Programs; protected override async Task OnInitializedAsync() { await Task.Delay(2000); await LoadData(); } protected async Task LoadData() { //TaxPrograms = await Http.GetFromJsonAsync<TaxYear[]>("api/taxprograms"); //TaxPrograms = System.Array.Empty<TaxProgram>(); Programs = new List<TaxProgram> { new TaxProgram { MasterId = 1, Program = "Real Estate", Module = "RE", TaxYears = new List<TaxYear> { new TaxYear { MasterId = 1, ProgramId = 1, Year = 2020, }, new TaxYear { MasterId = 2, ProgramId = 1, Year = 2019, }, }.AsEnumerable() }, new TaxProgram { MasterId = 2, Program = "Per Capita", Module = "RE", TaxYears = new List<TaxYear> { new TaxYear { MasterId = 3, ProgramId = 2, Year = 2020, }, new TaxYear { MasterId = 4, ProgramId = 2, Year = 2019, }, }.AsEnumerable() } }.AsEnumerable(); Program = Programs.FirstOrDefault(); ProgramCount = Programs.Count(); await Task.Yield(); } }
These are the two models:
public class TaxProgram { [Key] public int MasterId; public string Module; public string Program; public IEnumerable<TaxYear> TaxYears { get; set; } } public class TaxYear { [Key] public int MasterId; [ForeignKey("MasterId")] public int ProgramId; public short Year; }