In a blazor server project i am using a TelerikPDFViewer control inside of a blazor bootstrap offcanvas control. The idea is that by clicking on a button within a grid a method is called that will:
- Take the ID of the entry in row that was clicked, and call a method that fetches the data that can display the entry as a pdf
- Assign the pdf data to an object that holds it, this object is in turn what the TelerikPDFViewer control is bound to
- Call the ShowAsync method of the offcanvas control to make the offcanvas appear on screen, thereby displaying the PDF
The issue i am having is that when the ShowAsync method is called with await, the displayed PDF does not refresh. If i omit the await keyword on this method then it does refresh but i do not understand why.
Below is the method that is called when the grid row button is clicked. As it is the PDF is displayed correctly the first time it is called but when clicking buttons from other rows in the grid, the displayed PDF does not change. However if i remove the await keyword from pdfViewerWindow.ShowAsync(); then it does refresh correctly each time.
private async Task ViewTOPCasePDFHandler(GridCommandEventArgs args)
{
TOPCase item = args.Item as TOPCase; //Get item from row in whihc the View PDF button was clicked
string pdfBase64String = await _topService.GenerateFormCompletedPDF(item.CaseID); //Call method to get the PDF content
pdfViewerModel = new PdfViewerModel() //Assign PDF content to model that is in turn bound to the Telerik PDF Viewer
{
PdfSource = Convert.FromBase64String(pdfBase64String),
DownloadFilename = Convert.ToDateTime(item.CreatedDate).ToString("yyyy_MM_dd") + "_MyForm_" + item.CaseID.ToString()
};
await pdfViewerWindow.ShowAsync(); //Show the offcanvas panel
}