Marty
Marty

Reputation: 11

Component not updating when one-way databound property updated

I'm having a heck of a time understanding why my component's UI will not re-render when a simple one-way databound property (List) is updated. I have other routable components re-rendering using the same approach without issue, but this non-routable component does not seem to want to behave the same way? It is my understanding that the component should update WITHOUT having to call StateHasChanged() on either onclick events.

@inherits Aivia.Bases.AltitudePage;

@inject IAlertService _alertService
@inject IJSRuntime _js;

@if (dsAlerts != null && dsAlerts.Any())
{
    <div class="alerts mt-3">
        <div class="container">
            @foreach (var dto in dsAlerts)
            {
                <div class="alert alert-primary p-3" role="alert">
                    <div class="row g-0">
                        <div class="col-auto icon">
                            <i class="fa-solid fa-comments"></i>
                        </div>
                        <div class="col">
                            <div class="title">
                                @dto.Title
                            </div>
                            
                            <div class="description">
                                @dto.Description
                            </div>

                            <div class="actions">
                                <button type="button" class="btn btn-primary" onclick="@(() => Read(dto))">
                                    <i class="fa-regular fa-circle-check me-2"></i>
                                    Dismiss
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            }
        </div>
    </div>
}

@code {

    private IEnumerable<dtoAlert> dsAlerts = Enumerable.Empty<dtoAlert>();

    protected override void OnInitialized()
    {
        GetAlerts();
    }

    private void GetAlerts()
    {
        this.dsAlerts = _alertService.queryUnreadAlerts(this.UserID).OrderBy(x => x.CreatedOn).ToList();
    }
    
    private void Read(dtoAlert dto)
    {
        _alertService.Read(this.UserID, dto.ID);
        GetAlerts();
    }
    
}

Upvotes: 0

Views: 57

Answers (1)

Marty
Marty

Reputation: 11

onclick="@(() => Read(dto))" simply needed to be @onclick="@(() => Read(dto))"

Upvotes: 1

Related Questions