-
Notifications
You must be signed in to change notification settings - Fork 59
Description
Describe the bug
When right-clicking an element that should display the custom context menu, it instead throws an error in the browser console 'Uncaught SyntaxError
Uncaught SyntaxError: "undefined" is not valid JSON
at JSON.parse (<anonymous>)
at d.OnContextMenu (blazorContextMenu.min.js:1:1302)
at HTMLDivElement.oncontextmenu (NewSheet:1:19)
I should also mention that I followed the setup instructions to the best of my abilities, but my app structure is not the same as in the given instructions. I have a Blazor server-side app targeting .NET 8. The instructions say "Add the following static file references in your _Host.cshtml (server-side blazor) ". My app doesn't have a _Host.cshtml file, but it does have App.razor so I tried this
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<base href="/" />
<link rel="stylesheet" href="css/app.css" />
<link rel="stylesheet" href="css/theme-dark.css" />
<link rel="stylesheet" href="FreedomSheetsApp.styles.css" />
<link rel="icon" type="image/png" href="favicon.png" />
<link href="_content/Blazor.ContextMenu/blazorContextMenu.min.css" rel="stylesheet" />
<script src="_content/Blazor.ContextMenu/blazorContextMenu.min.js"></script>
<HeadOutlet />
</head>
<body>
<Routes />
<script src="_framework/blazor.web.js"></script>
</body>
</html>
I also tried doing it in MainLayout.razor, but that didn't work either. Is it possible to use the custom context menu in this type of project, or is it required to have a _Host.cshtml file?
To Reproduce
Steps to reproduce the behavior:
- Create a new (or use existing) Blazor server-side app targeting .NET 8.
- Follow the setup instructions for installing the NuGet package and setup, except use App.razor instead of _Host.cshtml.
- Run the app and try to use the custom context menu. It displays the standard browser context menu instead of the custom one.
Expected behavior
Display custom context menu.
Screenshots

Desktop (please complete the following information):
- OS: Windows 11
- Browser: Edge
- Version: 2.1