Trying to implement an offcanvas window form and ensuring it stays open only when the user clicks the close button. Following client requirements, I need to call the offcanvas window via C# with IJSRuntime injection instead of directly from HTML.
Operating on .NET 8 using Blazor framework, below are the code snippets:
Razor file snippet:
<button class="btn btn-primary" type="button" data-bs-dismiss="offcanvas" data-bs-backdrop="static" @onclick="() => ShowCanvas()">Show Canvas</button>
C# method block:
async void ShowCanvas()
{
await JS.InvokeVoidAsync("showOffCanvas");
}
Javascript function snippet:
function showOffCanvas() {
var myCanvas = new bootstrap.Offcanvas(document.getElementById('offcanvasWindow'));
myCanvas.show();
}
Encountered an exception during application run, details below:
Microsoft.JSInterop.JSException: 'OFFCANVAS: Option "backdrop" provided type "string" but expected type "boolean".
TypeError: OFFCANVAS: Option "backdrop" provided type "string" but expected type "boolean".
(Additional error stack trace provided)
Any suggestions for resolving this issue using IJSRuntime method?
Thank you.
Tried omitting data-bs-dismiss="offcanvas" attribute and modified JS code as follows:
function showModalItemMasterForm() {
var myCanvas = new bootstrap.Offcanvas(document.getElementById('offcanvasWindow'),
{ backdrop: 'static', keyboard: false });
myCanvas.show();
}
However, encountering the same error message.