在我的 Blazor 服务器应用程序中,我有一个带有 BlazorStrap 轮播的页面和一个用于下载 zip 文件的按钮。Carousel 工作正常,可以毫无问题地循环播放所有图像,直到我单击按钮下载 zip 文件。zip 文件正确下载,但之后我在控制台中收到此错误:
错误:System.ArgumentOutOfRangeException:索引超出范围。必须是非负数且小于集合的大小。Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task
) 在 Microsoft.AspNetCore .Components.RenderTree.Renderer.GetErrorHandledTask(任务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");
}
编辑:我忘了补充说我的渲染模式是 Server 而不是 ServerPrerendered。