Try to apply
asp.net-core
How to get HttpContext on Radzen project envrionment?
public async Task ExportExcel(){
IWorkbook workbook;
workbook = new XSSFWorkbook();
ISheet excelSheet = workbook.CreateSheet("Test");
IRow row = excelSheet.CreateRow(0);
row.CreateCell(0).SetCellValue("ID");
row.CreateCell(1).SetCellValue("Name");
row = excelSheet.CreateRow(1);
row.CreateCell(0).SetCellValue(1);
row.CreateCell(1).SetCellValue("User 1");
workbook.WriteExcelToResponse(HttpContext,"test.xlsx");
}
All Radzen applications are generic Blazor (ASP.NET Core ones). All approaches to get HttpContext will work in a Radzen application. Try searching online.
1 Like
If you want to get the context in a controller class then the controller has the current HttpContext as a property.
How about from Radzen generated set, files as follows
PROG.razor
PROG.razor.cs
PROG.razor.designer.cs
Try to cast httpContextAccessor but failed
[Inject] Microsoft.AspNetCore.Http.IHttpContextAccessor httpContextAccessor { get; set; }
The solution from the stackoverflow question won't work in a Blazor page. You cannot stream a file from Blazor. Other than that searching on google for "HttpContext Blazor" returned this: https://stackoverflow.com/questions/53817373/how-do-i-access-httpcontext-in-server-side-blazor/53819045
1 Like