Cascading primitive type values to Blazored.Modal

265 Views Asked by At

Blazored.Modal's document is very helpful in regards to passing parameters from "base" to modal. However, We have some trouble to update primitive types from base to modal.

In base (which will call the modal) we have

    [CascadingParameter]
    public bool IsTodayFriday { get; set; }

    [CascadingParameter]
    public Employee employee { get; set; }

    [CascadingParameter]
    public IModalService iModal { get; set; } = default!;

And to pass parameters to Modal:

        var emp= new Employee();
        var parameters = new ModalParameters()
            .Add(nameof(emp), emp)
            .Add(nameof(IsTodayFriday ), IsTodayFriday );
        
        iModal.Show<CheckDateAndLeaveEarly>("Get off early?", parameters);

In the Modal.razor.cs, decorate the parameters properly:

    [Parameter]
    public bool IsTodayFriday { get; set; }

    [Parameter]
    public Employee employee{ get; set; }

    [CascadingParameter]
    public IModalService iModal { get; set; } = default!;

And that will pass all necessary parameters to the modal. However, the "IsTodayFriday " is passed by value instead of reference, so when the source changed, this value remains the same. I think I can wrap it up in some sort of object and pass by reference. But is there a simpler way to cascade the primitive type values?

0

There are 0 best solutions below