Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

259
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!