我正在尝试在我的 blazor 服务器端应用程序上添加导出到 excel 按钮。到目前为止,在梳理互联网之后,这就是我所做的。
我的按钮
<div class="row text-right">
<div class="col-12 p-3">
<button class="btn btn-outline-success" @onclick="@(() =>DownloadExcel(formValues.Region, formValues.startDate, formValues.endDate))">
Export to Excel
<i class="fa fa-file-excel" aria-hidden="true"></i>
</button>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我的 .razor 页面中的方法
public FileResult DownloadExcel(string Region, DateTime StartDate, DateTime EndDate)
{
FileResult ExcelFile = searchService.ExportToExcel(Region, StartDate, EndDate);
return ExcelFile;
}
Run Code Online (Sandbox Code Playgroud)
最后我的服务逻辑
public FileResult ExportToExcel(string Region, DateTime StartDate, DateTime EndDate)
{
var queryable = context.AuditCardPinrecords.Where(s => Region == s.RegionRecordId)
.Where(s => s.AuditComplete == true)
.Where(s => s.DateTime >= StartDate && s.DateTime …Run Code Online (Sandbox Code Playgroud)