Search code examples
blazorblazor-webassemblymudblazor

Am I missing an import for ActivatorContent in Blazor (hosted WASM using .NET 6)?


I'm currently working on a self-study project that uses Blazor, and I'm trying to create a page for image uploads (code shown below):

@page "/images/add"

<h3>Add Image</h3>

<MudFileUpload T="IBrowserFile" Accept=".png, .jpg" FilesChanged="UploadFile" MaximumFileCount="100">
    <ActivatorContent>
        <MudButton Variant="Variant.Filled" Color="Color.Primary" StartIcon="@Icons.Material.Filled.CloudUpload">
            Upload Image
        </MudButton>
    </ActivatorContent>
</MudFileUpload>

@code {
    IList<IBrowserFile> _files = new List<IBrowserFile>();

    void UploadFile(IBrowserFile file)
    {
        _files.Add(file);
        
        // Add image file to storage
    }
}

This is essentially just following the tutorial page on File Uploads from the MudBlazor website (see here).

However, the <ActivatorContent> tags don't seem to be recognised by my IDE (Visual Studio) and the button does not render when I run the project.

Am I missing an import or a using somewhere? This feels like the fix should be fairly obvious... thanks!


Solution

  • Since you are using .NET 6, you won't be able to use the latest version of MudBlazor (i.e. v7). The documentation you provided is for MudBlazor v7, in which the File Upload component was updated to include ActivatorContent.

    Refer instead to the MudBlazor v6 documentation where ButtonTemplate should be used instead.

    Alternatively, if this is a new project, simply use .NET 8 if that's an option.