私の Blazor サーバー アプリケーションには、BlazorStrap カルーセルと zip ファイルをダウンロードするためのボタンを含むページがあります。カルーセルは問題なく動作し、ボタンをクリックして zip ファイルをダウンロードするまで、問題なくすべての画像をループできます。zip ファイルは正しくダウンロードされますが、その後、コンソールに次のエラーが表示されます。
エラー: System.ArgumentOutOfRangeException: インデックスが範囲外でした。負ではなく、コレクションのサイズより小さくなければなりません。
Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(タスク タスク) の Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(タスク タスク)の BlazorStrap.BSCarouselBase.AnimationEnd(BSCarouselItemBase 送信者) の System.Collections.Generic.List`1.get_Item(Int32 インデックス) の (パラメーター 'インデックス') .Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle)
私のカルーセルとダウンロードファイルボタンのHTML:
<BlazorStrap.BSCarousel NumberOfItems="@slideshowImages.Count" style="width: 23vw;">
<div class="carousel-inner">
@foreach (var item in slideshowImages)
{
<BlazorStrap.BSCarouselItem Src="@item.Source" Alt="@item.Alt" style="width: 100%;">
@if (bShowImageTitle == true)
{
<BlazorStrap.BSCarouselCaption CaptionText="@item.Caption.Split('.')[0]" />
}
</BlazorStrap.BSCarouselItem>
}
</div>
<BlazorStrap.BSCarouselControl CarouselDirection="BlazorStrap.CarouselDirection.Previous" NumberOfItems="@slideshowImages.Count" />
<BlazorStrap.BSCarouselControl CarouselDirection="BlazorStrap.CarouselDirection.Next" NumberOfItems="@slideshowImages.Count" />
</BlazorStrap.BSCarousel>
<button class="btn btn-primary bold" type="button" @onclick="(e => btnDownloadAllClick())">DOWNLOAD FILES</button>
カルーセル アイテムを取得するためのコード:
List<Slideshow> slideshowImages = new List<Slideshow>();
public class Slideshow
{
public string Source { get; set; }
public string Alt { get; set; }
public string Caption { get; set; }
public string Header { get; set; }
}
public int iImageCount;
protected override void OnInitialized()
{
//here i'm getting the images from a folder in azure storage, this works fine
List<string> tempList = clsBlobService.ListBlobs(folderPath);
foreach (var img in tempList)
{
Slideshow tempItem = new Slideshow
{
Source = rootPath + img,
Alt = img.Split('/').Last(),
Caption = img.Split('/').Last()
};
slideshowImages.Add(tempItem);
}
iImageCount = slideshowImages.Count;
}
ファイルのダウンロード ボタンがクリックされたときのコード:
public async void btnDownloadAllClick()
{
await JSRuntime.InvokeVoidAsync("open", "/Temp/MyZipFile.zip");
}
編集:レンダリングモードがサーバーであり、ServerPrerendered ではないことを追加するのを忘れていました。