0
votes

enter image description hereI have a blazor server app which generates xml files to a specific directory. I am displaying the list of files on a table to make it downloadable but it doesn't work.

@if (Files != null)
{
    <table class="table">
        <thead>
            <tr>
                <th>Files</th>
                <th> </th>
            </tr>

        </thead>
        <tbody>
            @foreach (var item in Files)
            {
                <tr>
                    <td>@item.Name </td>
                    <td> <a href="@item.FullName" download>Download</a> </td>
                </tr>
            }

        </tbody>
    </table>
}
2

2 Answers

0
votes

Since there is no code to populate the Files variable, it will always be null. You would have to do that in an event handler or life-cycle event.

0
votes

Try to call IJSRuntime through a function as

@inject IJSRuntime  js`

@code{
  void Download(string fileName
  await js.InvokeVoidAsync("downloadFile",fileName)
}
_Host.cshtml
function downloadFile(fileName) {
     location.href = fileName;
}