Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

260
Visualizações
How can I call the boolean from c# to Javascript Ajax?

I was trying to call the boolean from my Controller which is true, But when I call it now on my Javascript ajax I can't get it.

$.ajax({
    url: "/Shop/Accessories",
    contentType: "application/html; charset=utf-8",
    type: 'GET',
    dataType: "html",
    success: (function (result) {
        if (result) { //If I do result == true : still not working
            $('#owl1').html(result)
            $('#owl1').owlCarousel({
                loop: true,
                nav: false,
                dots: false,
                autoplay: false,
                margin: 10,
                responsive: {
                    0: {
                        items: 2
                    },
                    600: {
                        items: 3
                    },
                    1000: {
                        items: 4
                    }
                }
            })
        } else {
            $(".noItem1").html(result);
        }
    }),
    error: (function (xhr, status) {
        alert(status);
    })
})

I am using a dataType: html for the return View when the database doesn't have any data

using (SqlConnection con = new SqlConnection(constring))
        {
            string command = "select item_image, item_name, item_price item_number, item_type, date_added from cooking_items";

            con.Open();
            using (SqlCommand cmd = new SqlCommand(command, con))
            {
                cmd.CommandTimeout = 60;
                SqlDataReader Creader1;
                Creader1 = cmd.ExecuteReader();
                if (Creader1.HasRows == true)
                {
                    con.Close();
                    con.Open();
                    DataTable dt = new DataTable();
                    using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                    {
                        da.Fill(dt);
                    }
                    con.Close();
                    return View("Cooking", dt);
                }
                else
                {
                    return View("Cooking"); //When there's no data, these is the one who should call my ajax.
                }
            }
        }
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda