Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

How to use [CascadingParameter] IMudDialogInstance with user type for child

$
0
0

I am new to Blazor / MudBlazor. I clearly do not understand how Blazor works!

I am attempting to start a child component (a MudBlazor dialog) from a parent component and pass a user data type (class rMidiDataBlazor) from the parent to the child.

namespace RiverDingo.Services.rMidiDataBase{    //ROB: For Blazor    public class rMidiDataBlazor     {        public System.String Field0 { get; set; }        public System.String Field1 { get; set; }        public System.String Field2 { get; set; }        public System.String Field3 { get; set; }        public System.String Field4 { get; set; }        public System.String Field5 { get; set; }        public System.String Field6 { get; set; }        public rMidiDataBlazor()         {        }        public rMidiDataBlazor ShallowCopy()        {            return ((rMidiDataBlazor)this.MemberwiseClone());        }    }}

Relevant RiverDingoInvoices.razor.cs:

private async Task RowClicked(DataGridRowClickEventArgs<rMidiDataBlazor> args){    var Parameters = new DialogParameters<RiverDingoInvoiceEdit>();    // args.Item is a rMidiDataBlazor class. It is there.    Parameters.Add("DataBlazor",(rMidiDataBlazor)args.Item);    var DialogReference = await DialogService.ShowAsync<RiverDingoInvoiceEdit>("Edit Invoice", Parameters);    var Result = await DialogReference.Result;    if (Result.Canceled == false)    {        this.GetRiverDingoData();    }}

Relevant RiverDingoInvoiceEdit.razor.cs:

public partial class RiverDingoInvoiceEdit{    private rMidiDataBlazor DataBlazor { get; set; }    [CascadingParameter]     IMudDialogInstance MudDialog { get; set; }}

RiverDingoInvoiceEdit.razor:

@using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage@inject IConfiguration Configuration@inject ProtectedSessionStorage ProtectedSessionStore@using global::RiverDingo.Services.rMidiDataBase;@inject IrMidiDataBaseClass MyDataBase;<MudDialog><DialogContent><MudForm @ref="Form" @bind-IsValid="@ValidationSuccess" @bind-Errors="@Errors"><MudText>Edit Invoice</MudText><MudTextField T="string" Label="Invoice Title:" @bind-Value="DataBlazor.Field2" Variant="Variant.Text" MaxLength="50"                          Required="true" RequiredError="You must supply an Invoice Title" /><MudTextField T="string" Label="Cost:" @bind-Value="DataBlazor.Field4" Variant="Variant.Text" MaxLength="7"                          Required="true" RequiredError="You must supply an Invoice Cost"                          Mask="@(new PatternMask("0000.00"))" /><MudDatePicker Label="Invoice Date" @bind-Value="DataBlazor.Field3" AutoClose="true" /><MudTextField T="string" Label="Notes:" @bind-Value="DataBlazor.Field5" Variant="Variant.Text" MaxLength="250" Lines="6"></MudTextField><MudTextField T="string" Label="Invoice Copy:" @bind-Value="InvoiceCopy" Variant="Variant.Text" MaxLength="100"></MudTextField></MudForm></DialogContent><DialogActions><MudButton OnClick="Cancel">Cancel</MudButton><MudButton Color="Color.Success" Variant="Variant.Filled" OnClick="Submit">Update Invoice Record</MudButton></DialogActions></MudDialog>

When I run the application and attempt to access RiverDingoInvoiceEdit, it fails. The ouput debug window contains:

warn: Microsoft.AspNetCore.Components.Server.Circuits.RemoteRenderer[100]      Unhandled exception rendering component: Object of type 'RiverDingo.Components.Pages.RiverDingo.Invoices.RiverDingoInvoiceEdit' has a property matching the name 'DataBlazor', but it does not have [Parameter], [CascadingParameter], or any other parameter-supplying attribute.      System.InvalidOperationException: Object of type 'RiverDingo.Components.Pages.RiverDingo.Invoices.RiverDingoInvoiceEdit' has a property matching the name 'DataBlazor', but it does not have [Parameter], [CascadingParameter], or any other parameter-supplying attribute.         at Microsoft.AspNetCore.Components.Reflection.ComponentProperties.ThrowForUnknownIncomingParameterName(Type targetType, String parameterName)         at Microsoft.AspNetCore.Components.Reflection.ComponentProperties.SetProperties(ParameterView& parameters, Object target)         at Microsoft.AspNetCore.Components.ComponentBase.SetParametersAsync(ParameterView parameters)         at Microsoft.AspNetCore.Components.Rendering.ComponentState.SupplyCombinedParameters(ParameterView directAndCascadingParameters)fail: Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost[111]      Unhandled exception in circuit 'P0prIIOPefmTKtojfTdeyxJAKEBlDc8Ms838lXRAlqA'.      System.InvalidOperationException: Object of type 'RiverDingo.Components.Pages.RiverDingo.Invoices.RiverDingoInvoiceEdit' has a property matching the name 'DataBlazor', but it does not have [Parameter], [CascadingParameter], or any other parameter-supplying attribute.         at Microsoft.AspNetCore.Components.Reflection.ComponentProperties.ThrowForUnknownIncomingParameterName(Type targetType, String parameterName)         at Microsoft.AspNetCore.Components.Reflection.ComponentProperties.SetProperties(ParameterView& parameters, Object target)         at Microsoft.AspNetCore.Components.ComponentBase.SetParametersAsync(ParameterView parameters)         at Microsoft.AspNetCore.Components.Rendering.ComponentState.SupplyCombinedParameters(ParameterView directAndCascadingParameters)

I do not understand how to pass class rMidiDataBlazor to the child dialog. Any help would be greatly appreciated


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>