I need to send from JS to .NET bool type when clicking on any part of the site, except for necessary classes, so that the div is closed inside @if statement.
I copied some information from here How do I call a C# method with parameters from JavaScript in Blazor WebAssembly?, but he didn't help much with my problem due to insufficient experience with JSInterop.
In C# script, menu opens without difficulties, only issues went with JS. That's why I need help. (Of course, I can remove @if and make closing and opening assignment all classes, but it seems to me this is a "crutch")
Thanks for answers!
HTML:
<button @onclick="ToggleMenu">
@if(!_collapseNavMenu)
{
Something
}
C#:
public static bool _collapseNavMenu { get; set; }
private void ToggleMenu()
{
_collapseNavMenu = !_collapseNavMenu;
}
[JSInvokable]
public static void CheckBool(bool check)
{
_collapseNavMenu = check;
}
private async Task OnBtn()
{
await js.InvokeAsync<object>("TestJs");
}
JS:
var jsCheck = true;
window.onclick = function(event) {
var dropdowns = document.getElementsByClassName("header__buttons");
var i;
if (!event.target.matches('.js-close')) {
if (jsCheck === true) {
function TestJs() {
var check = true;
DotNet.invokeMethod('Heaven', 'CheckBool', check);
}
TestJs();