ExpandRow not working with data retrieved from localStorage

Hi,

I have reason to believe that there might be a bug in the ExpandRow method of the DataGrid.

Code block 1:

<RadzenDataGrid Id="surveytable" @ref="_surveys" Data="@_ongoingSurveys" TItem="OngoingSurveysOverviewModel" @bind-Settings="@OngoingSettings"
                    AllowColumnResize="true" AllowAlternatingRows="true" AllowPaging="true" PageSize="10" ExpandMode="DataGridExpandMode.Single"
                    AllowSorting="true" AllowMultiColumnSorting="true" AllowFiltering="true" FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive" 
                    RowClick="OnSurveyRowClick" RowExpand="SaveExpandedRow" RowCollapse="RemoveExpandedRow">

When a user clicks on the expand/collapse icon in the first column of the grid it triggers the RowExpand or RowCollapse EventCallback.
I mimic the same behaviour in the RowClick where I execute the ExpandRow method which then triggers the correct EventCallback.

Code block 2:

private async void OnSurveyRowClick(DataGridRowMouseEventArgs<OngoingSurveysOverviewModel> surveyRow)
{
  if (_rowClicked)
  {
    await _surveys.ExpandRow(surveyRow.Data);
  }
  _rowClicked = true;
}

private async Task SaveExpandedRow(OngoingSurveysOverviewModel? row)
{
  if (_expandRowOnInit)
  {
    _expandRowOnInit = false;
  }
  else
  {
    await JsRuntime.InvokeVoidAsync("window.localStorage.setItem", "ExpandedRow", JsonSerializer.Serialize(row));
    _expandedRow = row;
  }
}

private async Task RemoveExpandedRow(OngoingSurveysOverviewModel row)
{
  await Task.CompletedTask;
  await JsRuntime.InvokeVoidAsync("window.localStorage.setItem", "ExpandedRow", null);
  _expandedRow = null;
}

When the user navigates away from the page and returns, or executes an update of the page it should reload the expanded row.
In order to achieve that I get the expanded row by executing the LoadExpandRowAsync in the OnInitialized state.
FYI, SetDataAsync will load the necessary data from the database in the _ongoingSurveys IEnumerable.

Code block 3:

private bool _expandRowOnInit;
IEnumerable<OngoingSurveysOverviewModel> _ongoingSurveys = new List<OngoingSurveysOverviewModel>();

protected override async Task OnInitializedAsync()
{
  await base.OnInitializedAsync();
  await SetDataAsync();
  await LoadExpandedRowAsync();
  _isSetData = false;
  _isLoading = false;
}

private async Task LoadExpandedRowAsync()
{
  await Task.CompletedTask;
  var result = await JsRuntime.InvokeAsync<string>("window.localStorage.getItem", "ExpandedRow");
  _expandedRow = !string.IsNullOrEmpty(result) ? JsonSerializer.Deserialize<OngoingSurveysOverviewModel>(result) : null;

  if (_expandedRow != null)
  {
    _expandRowOnInit = true;
  }
}

After that I use OnAfterRenderAsync to execute the ExpandRow method there which should then expand the correct row, this only needs to be achieved when private bool _expandRowOnInit is true.
This will also trigger the RowExpand EventCallback, but to prevent it from saving the same data to the localStorage I check if _expandRowOnInit is true, if so it should set it to false and return. (see Code block 2)

Code Block 4:

private bool _expandRowOnInit;
IEnumerable<OngoingSurveysOverviewModel> _ongoingSurveys = new List<OngoingSurveysOverviewModel>();
RadzenDataGrid<OngoingSurveysOverviewModel?> _surveys = new ();

protected override async Task OnAfterRenderAsync(bool firstRender)
{
  await base.OnAfterRenderAsync(firstRender);
  
  if (firstRender)
  {
    await LoadStateAsync();
    StateHasChanged();
  }

  if (_expandRowOnInit)
  {
    await _surveys.ExpandRow(_ongoingSurveys.FirstOrDefault(x => _expandedRow != null && x.SurveyId == _expandedRow.SurveyId));
  }
}

Debugging shows me that in OnAfterRender the Expand method receives the correct row to be expanded but doesn't execute the command.

Kind regards
TinoS

I don't think executing any code in OnAfterRenderAsync would lead to UI update unless you also call StateHasChanged() (similar to the existing code in the if statement). And make sure not to call it always as it will lead to endless loop.

I adjusted my code as per your feedback but it still doesn't expand the correct row.
The _expandRowOnInit prevents me from going into an infinite loop.

  if (_expandRowOnInit && _expandedRow != null)
  {
    await _surveys.ExpandRow(_expandedRow);
    StateHasChanged();
  }

Any ideas as to why this does behave as expected?

Probably because _expandedRow is not part of the collection which your grid displays. You can find the actual item from it and use it instead.

var expandedRow = _ongoingSurveys.FirstOrDefault(e => e.ID == _expandedRow.ID);
_surveys.ExpandRow(expandedRow);

I applied the logic that you suggested, but still without success.

  if (_expandRowOnInit && _expandedRow != null)
  {
    var expandedRow = _ongoingSurveys.FirstOrDefault(s => s.SurveyId == _expandedRow.SurveyId);
    await _surveys.ExpandRow(expandedRow);
    StateHasChanged();
  }

The correct row is found in the _ongoingSurveys IEnumerable, but the ExpandRow doesn't expand it.

Our online demo uses very similar code and works as expected. Make sure the row you want to expand is on the current page as well.

I've just visited the online demo and edited the code and clicked run but it doesn't allow me to execute JsonSerialization.

Could you run the following code locally?

@using RadzenBlazorDemos.Data
@using RadzenBlazorDemos.Models.Northwind
@using Microsoft.EntityFrameworkCore
@using System.Text.Json

@inherits DbContextPage

@inject IJSRuntime JsRuntime

<RadzenDataGrid @ref="grid" AllowFiltering="true" AllowPaging="true" PageSize="3" AllowSorting="true" ExpandMode="DataGridExpandMode.Single"
                RowClick="OnOrderRowClick" RowExpand="SaveExpandedRow" RowCollapse="RemoveExpandedRow" Data="@orders" TItem="Order">
    <Template Context="order">
        <RadzenCard Style="margin-bottom:20px">
            Company:
            <b>@order.Customer?.CompanyName</b>
        </RadzenCard>
        <RadzenTabs>
            <Tabs>
                <RadzenTabsItem Text="Order Details">
                    <RadzenDataGrid AllowFiltering="true" AllowPaging="true" AllowSorting="true" Data="@order.OrderDetails" TItem="OrderDetail">
                        <Columns>
                            <RadzenDataGridColumn TItem="OrderDetail" Property="Order.CustomerID" Title="Order" />
                            <RadzenDataGridColumn TItem="OrderDetail" Property="Product.ProductName" Title="Product" />
                            <RadzenDataGridColumn TItem="OrderDetail" Property="UnitPrice" Title="Unit Price">
                                <Template Context="detail">
                                    @String.Format(new System.Globalization.CultureInfo("en-US"), "{0:C}", detail.UnitPrice)
                                </Template>
                            </RadzenDataGridColumn>
                            <RadzenDataGridColumn TItem="OrderDetail" Property="Quantity" Title="Quantity" />
                            <RadzenDataGridColumn TItem="OrderDetail" Property="Discount" Title="Discount">
                                <Template Context="detail">
                                    @String.Format("{0}%", detail.Discount * 100)
                                </Template>
                            </RadzenDataGridColumn>
                        </Columns>
                    </RadzenDataGrid>
                </RadzenTabsItem>
                <RadzenTabsItem Text="Products">
                    <RadzenDataList WrapItems="true" AllowPaging="true" Data="@order.OrderDetails" TItem="OrderDetail" PageSize="10">
                        <Template Context="detail">
                            <RadzenCard Style="width:100px; height:100px">
                                <h4 class="text-thin">Product</h4>
                                <b>@detail?.Product?.ProductName</b>
                            </RadzenCard>
                        </Template>
                    </RadzenDataList>
                </RadzenTabsItem>
            </Tabs>
        </RadzenTabs>
    </Template>
    <Columns>
        <RadzenDataGridColumn TItem="Order" Property="OrderID" Title="Order ID" Width="120px" />
        <RadzenDataGridColumn TItem="Order" Property="Customer.CompanyName" Title="Customer" Width="200px" />
        <RadzenDataGridColumn TItem="Order" Property="Employee.LastName" Title="Employee" Width="200px">
            <Template Context="order">
                <RadzenImage Path="@order.Employee?.Photo" style="width: 32px; height: 32px; border-radius: 16px; margin-right: 6px;" AlternateText="@(order.Employee?.FirstName + " " + order.Employee?.LastName)" />
                @order.Employee?.FirstName @order.Employee?.LastName
            </Template>
        </RadzenDataGridColumn>
        <RadzenDataGridColumn TItem="Order" Property="OrderDate" Title="Order Date" FormatString="{0:d}" Width="140px" />
        <RadzenDataGridColumn TItem="Order" Property="RequiredDate" Title="Required Date" FormatString="{0:d}" Width="140px" />
        <RadzenDataGridColumn TItem="Order" Property="ShippedDate" Title="Shipped Date" FormatString="{0:d}" Width="140px" />
        <RadzenDataGridColumn TItem="Order" Property="ShipName" Title="Ship Name" />
        <RadzenDataGridColumn TItem="Order" Property="ShipCountry" Title="Ship Country" />
    </Columns>
</RadzenDataGrid>

@code {
    IEnumerable<Order> orders;
    RadzenDataGrid<Order> grid;
    private bool _rowClicked = true;
    private bool _expandRowOnInit;
    Order _expandedRow;

    protected override async Task OnInitializedAsync()
    {
        await base.OnInitializedAsync();
        await LoadExpandedRowAsync();
        orders = dbContext.Orders.Include("Customer").Include("Employee").Include("OrderDetails").Include("OrderDetails.Product").ToList();
    }

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        await base.OnAfterRenderAsync(firstRender);
 
        if (_expandRowOnInit && _expandedRow != null)
        {
            var expandedRow = orders.FirstOrDefault(o => o.OrderID == _expandedRow.OrderID);
            await grid.ExpandRow(expandedRow);
            StateHasChanged();
        }
    }

    private async void OnOrderRowClick(DataGridRowMouseEventArgs<Order> orderRow)
    {
        if (_rowClicked)
        {
            await grid.ExpandRow(orderRow.Data);
        }
        _rowClicked = true;
    }
    
    private async Task SaveExpandedRow(Order orderRow)
    {
        if (_expandRowOnInit)
        {
            _expandRowOnInit = false;
        }
        else
        {
            await JsRuntime.InvokeVoidAsync("window.localStorage.setItem", "ExpandedRow", JsonSerializer.Serialize(orderRow));
            _expandedRow = orderRow;
        }
    }

    private async Task RemoveExpandedRow(Order orderRow)
    {
        await Task.CompletedTask;
        await JsRuntime.InvokeVoidAsync("window.localStorage.setItem", "ExpandedRow", null);
        _expandedRow = null;
    }

    private async Task LoadExpandedRowAsync()
    {
        await Task.CompletedTask;
        var result = await JsRuntime.InvokeAsync<string>("window.localStorage.getItem", "ExpandedRow");
        _expandedRow = !string.IsNullOrEmpty(result) ? JsonSerializer.Deserialize<Order>(result) : null;

        if (_expandedRow != null)
        {
            _expandRowOnInit = true;
        }
    }
}

I think this would be the closest to check the behaviour that we can get.

This code is not working.

  1. You can't use JavaScript interop during OnInitializedAsync
  2. The serialization fails because there are object cycles (Order -> Customer -> Orders).

This does work though:

@using RadzenBlazorDemos.Data
@using RadzenBlazorDemos.Models.Northwind
@using Microsoft.EntityFrameworkCore
@using System.Text.Json
@using System.Text.Json.Serialization

@inherits DbContextPage

@inject IJSRuntime JsRuntime

<RadzenDataGrid @ref="grid" AllowFiltering="true" AllowPaging="true" PageSize="3" AllowSorting="true" ExpandMode="DataGridExpandMode.Single"
                RowClick="OnOrderRowClick" RowExpand="SaveExpandedRow" RowCollapse="RemoveExpandedRow" Data="@orders" TItem="Order">
    <Template Context="order">
        <RadzenCard Style="margin-bottom:20px">
            Company:
            <b>@order.Customer?.CompanyName</b>
        </RadzenCard>
        <RadzenTabs>
            <Tabs>
                <RadzenTabsItem Text="Order Details">
                    <RadzenDataGrid AllowFiltering="true" AllowPaging="true" AllowSorting="true" Data="@order.OrderDetails" TItem="OrderDetail">
                        <Columns>
                            <RadzenDataGridColumn TItem="OrderDetail" Property="Order.CustomerID" Title="Order" />
                            <RadzenDataGridColumn TItem="OrderDetail" Property="Product.ProductName" Title="Product" />
                            <RadzenDataGridColumn TItem="OrderDetail" Property="UnitPrice" Title="Unit Price">
                                <Template Context="detail">
                                    @String.Format(new System.Globalization.CultureInfo("en-US"), "{0:C}", detail.UnitPrice)
                                </Template>
                            </RadzenDataGridColumn>
                            <RadzenDataGridColumn TItem="OrderDetail" Property="Quantity" Title="Quantity" />
                            <RadzenDataGridColumn TItem="OrderDetail" Property="Discount" Title="Discount">
                                <Template Context="detail">
                                    @String.Format("{0}%", detail.Discount * 100)
                                </Template>
                            </RadzenDataGridColumn>
                        </Columns>
                    </RadzenDataGrid>
                </RadzenTabsItem>
                <RadzenTabsItem Text="Products">
                    <RadzenDataList WrapItems="true" AllowPaging="true" Data="@order.OrderDetails" TItem="OrderDetail" PageSize="10">
                        <Template Context="detail">
                            <RadzenCard Style="width:100px; height:100px">
                                <h4 class="text-thin">Product</h4>
                                <b>@detail?.Product?.ProductName</b>
                            </RadzenCard>
                        </Template>
                    </RadzenDataList>
                </RadzenTabsItem>
            </Tabs>
        </RadzenTabs>
    </Template>
    <Columns>
        <RadzenDataGridColumn TItem="Order" Property="OrderID" Title="Order ID" Width="120px" />
        <RadzenDataGridColumn TItem="Order" Property="Customer.CompanyName" Title="Customer" Width="200px" />
        <RadzenDataGridColumn TItem="Order" Property="Employee.LastName" Title="Employee" Width="200px">
            <Template Context="order">
                <RadzenImage Path="@order.Employee?.Photo" style="width: 32px; height: 32px; border-radius: 16px; margin-right: 6px;" AlternateText="@(order.Employee?.FirstName + " " + order.Employee?.LastName)" />
                @order.Employee?.FirstName @order.Employee?.LastName
            </Template>
        </RadzenDataGridColumn>
        <RadzenDataGridColumn TItem="Order" Property="OrderDate" Title="Order Date" FormatString="{0:d}" Width="140px" />
        <RadzenDataGridColumn TItem="Order" Property="RequiredDate" Title="Required Date" FormatString="{0:d}" Width="140px" />
        <RadzenDataGridColumn TItem="Order" Property="ShippedDate" Title="Shipped Date" FormatString="{0:d}" Width="140px" />
        <RadzenDataGridColumn TItem="Order" Property="ShipName" Title="Ship Name" />
        <RadzenDataGridColumn TItem="Order" Property="ShipCountry" Title="Ship Country" />
    </Columns>
</RadzenDataGrid>

@code {
    IEnumerable<Order> orders;
    RadzenDataGrid<Order> grid;
    private bool _rowClicked = true;
    private bool _expandRowOnInit;
    Order _expandedRow;

    protected override async Task OnInitializedAsync()
    {
        await base.OnInitializedAsync();
        orders = dbContext.Orders.Include("Customer").Include("Employee").Include("OrderDetails").Include("OrderDetails.Product").ToList();
    }

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        if (firstRender)
        {
            await LoadExpandedRowAsync();

            if (_expandRowOnInit)
            {
                var expandedRow = orders.FirstOrDefault(o => o.OrderID == _expandedRow.OrderID);
                _expandRowOnInit = false;
                await grid.ExpandRow(expandedRow);
                StateHasChanged();
            }
        }
    }

    private async void OnOrderRowClick(DataGridRowMouseEventArgs<Order> orderRow)
    {
        if (_rowClicked)
        {
            await grid.ExpandRow(orderRow.Data);
        }
        _rowClicked = true;
    }

    private async Task SaveExpandedRow(Order orderRow)
    {
        await JsRuntime.InvokeVoidAsync("window.localStorage.setItem", "ExpandedRow", JsonSerializer.Serialize(new { orderRow.OrderID }));
    }

    private async Task RemoveExpandedRow(Order orderRow)
    {
        await Task.CompletedTask;
        await JsRuntime.InvokeVoidAsync("window.localStorage.setItem", "ExpandedRow", null);
        _expandedRow = null;
    }

    private async Task LoadExpandedRowAsync()
    {
        var result = await JsRuntime.InvokeAsync<string>("window.localStorage.getItem", "ExpandedRow");
        _expandedRow = !string.IsNullOrEmpty(result) ? JsonSerializer.Deserialize<Order>(result) : null;

        if (_expandedRow != null)
        {
            _expandRowOnInit = true;
        }
    }
}

expand-row

I also use DatagridSettings to keep the filter state of the Grid.
Could that cause the problem?

I tried applying the code you returned to my application but still without success.

@using RadzenBlazorDemos.Data
@using RadzenBlazorDemos.Models.Northwind
@using Microsoft.EntityFrameworkCore
@using System.Text.Json
@using System.Text.Json.Serialization

@inherits DbContextPage

@inject IJSRuntime JsRuntime

<RadzenDataGrid @ref="grid" AllowFiltering="true" AllowPaging="true" PageSize="3" AllowSorting="true" ExpandMode="DataGridExpandMode.Single"
                RowClick="OnOrderRowClick" RowExpand="SaveExpandedRow" RowCollapse="RemoveExpandedRow" Data="@orders" TItem="Order" bind-Settings="@GridSettings">
    <Template Context="order">
        <RadzenCard Style="margin-bottom:20px">
            Company:
            <b>@order.Customer?.CompanyName</b>
        </RadzenCard>
        <RadzenTabs>
            <Tabs>
                <RadzenTabsItem Text="Order Details">
                    <RadzenDataGrid AllowFiltering="true" AllowPaging="true" AllowSorting="true" Data="@order.OrderDetails" TItem="OrderDetail">
                        <Columns>
                            <RadzenDataGridColumn TItem="OrderDetail" Property="Order.CustomerID" Title="Order" />
                            <RadzenDataGridColumn TItem="OrderDetail" Property="Product.ProductName" Title="Product" />
                            <RadzenDataGridColumn TItem="OrderDetail" Property="UnitPrice" Title="Unit Price">
                                <Template Context="detail">
                                    @String.Format(new System.Globalization.CultureInfo("en-US"), "{0:C}", detail.UnitPrice)
                                </Template>
                            </RadzenDataGridColumn>
                            <RadzenDataGridColumn TItem="OrderDetail" Property="Quantity" Title="Quantity" />
                            <RadzenDataGridColumn TItem="OrderDetail" Property="Discount" Title="Discount">
                                <Template Context="detail">
                                    @String.Format("{0}%", detail.Discount * 100)
                                </Template>
                            </RadzenDataGridColumn>
                        </Columns>
                    </RadzenDataGrid>
                </RadzenTabsItem>
                <RadzenTabsItem Text="Products">
                    <RadzenDataList WrapItems="true" AllowPaging="true" Data="@order.OrderDetails" TItem="OrderDetail" PageSize="10">
                        <Template Context="detail">
                            <RadzenCard Style="width:100px; height:100px">
                                <h4 class="text-thin">Product</h4>
                                <b>@detail?.Product?.ProductName</b>
                            </RadzenCard>
                        </Template>
                    </RadzenDataList>
                </RadzenTabsItem>
            </Tabs>
        </RadzenTabs>
    </Template>
    <Columns>
        <RadzenDataGridColumn TItem="Order" Property="OrderID" Title="Order ID" Width="120px" />
        <RadzenDataGridColumn TItem="Order" Property="Customer.CompanyName" Title="Customer" Width="200px" />
        <RadzenDataGridColumn TItem="Order" Property="Employee.LastName" Title="Employee" Width="200px">
            <Template Context="order">
                <RadzenImage Path="@order.Employee?.Photo" style="width: 32px; height: 32px; border-radius: 16px; margin-right: 6px;" AlternateText="@(order.Employee?.FirstName + " " + order.Employee?.LastName)" />
                @order.Employee?.FirstName @order.Employee?.LastName
            </Template>
        </RadzenDataGridColumn>
        <RadzenDataGridColumn TItem="Order" Property="OrderDate" Title="Order Date" FormatString="{0:d}" Width="140px" />
        <RadzenDataGridColumn TItem="Order" Property="RequiredDate" Title="Required Date" FormatString="{0:d}" Width="140px" />
        <RadzenDataGridColumn TItem="Order" Property="ShippedDate" Title="Shipped Date" FormatString="{0:d}" Width="140px" />
        <RadzenDataGridColumn TItem="Order" Property="ShipName" Title="Ship Name" />
        <RadzenDataGridColumn TItem="Order" Property="ShipCountry" Title="Ship Country" />
    </Columns>
</RadzenDataGrid>

@code {
    private bool _isSetData;

    IEnumerable<Order> orders;
    RadzenDataGrid<Order> grid;
    private bool _rowClicked = true;
    private bool _expandRowOnInit;
    Order _expandedRow;

    DataGridSettings? _gridSettings;

    private DataGridSettings? GridSettings
    {
      get => _gridSettings;
      set
      {
        if (_isSetData)
        {
          _isSetData = false;
          return;
        }
        _gridSettings= value;
        InvokeAsync(SaveStateAsync);
      }
    }

    protected override async Task OnInitializedAsync()
    {
        await base.OnInitializedAsync();
        await SetDataAsync();
        _isSetData = false;
    }

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        if (firstRender)
        {
	    await LoadStateAsync();
            await LoadExpandedRowAsync();

            if (_expandRowOnInit)
            {
                var expandedRow = orders.FirstOrDefault(o => o.OrderID == _expandedRow.OrderID);
                _expandRowOnInit = false;
                await grid.ExpandRow(expandedRow);
                StateHasChanged();
            }
        }
    }

    private async Task SetDataAsync()
    {
	orders = dbContext.Orders.Include("Customer").Include("Employee").Include("OrderDetails").Include("OrderDetails.Product").ToList();
        _isSetData = true;
    }

    private async Task SaveStateAsync()
    {
      await JsRuntime.InvokeVoidAsync("window.localStorage.setItem", "GridSettings", JsonSerializer.Serialize(GridSettings));
    }
  
    private async Task LoadStateAsync()
    {
      var result = await JsRuntime.InvokeAsync<string>("window.localStorage.getItem", "GridSettings");
      if (!string.IsNullOrEmpty(result))
      {
        _gridSettings = JsonSerializer.Deserialize<DataGridSettings>(result)!;
      }
    }

    private async void OnOrderRowClick(DataGridRowMouseEventArgs<Order> orderRow)
    {
        if (_rowClicked)
        {
            await grid.ExpandRow(orderRow.Data);
        }
        _rowClicked = true;
    }

    private async Task SaveExpandedRow(Order orderRow)
    {
        await JsRuntime.InvokeVoidAsync("window.localStorage.setItem", "ExpandedRow", JsonSerializer.Serialize(new { orderRow.OrderID }));
    }

    private async Task RemoveExpandedRow(Order orderRow)
    {
        await Task.CompletedTask;
        await JsRuntime.InvokeVoidAsync("window.localStorage.setItem", "ExpandedRow", null);
        _expandedRow = null;
    }

    private async Task LoadExpandedRowAsync()
    {
        var result = await JsRuntime.InvokeAsync<string>("window.localStorage.getItem", "ExpandedRow");
        _expandedRow = !string.IsNullOrEmpty(result) ? JsonSerializer.Deserialize<Order>(result) : null;

        if (_expandedRow != null)
        {
            _expandRowOnInit = true;
        }
    }
}

I am afraid I don't know how to help you further. The thread started as a potential bug related to localStorage. To me this isn't the case. If you think there is a bug in the Radzen.Blazor library you can attach its source to your application and try debugging the ExpandRow method. You can easily see if the datagrid settings are somehow related by just not using them.

Hi,

First of all thank you very much for taking your time in investigating this issue.
Handing me more insight in blazor lifecycles and alternative solutions made it possible for me to finetune the issue down to the way the data was loaded.

We execute a query which returns an IEnumerable. We then groupby and select to iterate over the viewitems and cast them to OngoingSurveysOverviewModels.
What caused the issue was that I forgot to add .ToList() after this select.

Rgds,
TinoS