Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

154
Vistas
Blazor return bool from JS

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();
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda