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

187
Visualizações
How to get onClick to work using html within C# server side code

I am try to get my onClick to work however my when I click nothing happens and no error to give insight as to what the problem might be

var data = new FormData();
            data.append("cart_list", new_cart);
            $.ajax({
            url: "@Url.Action("GetCart", "Home")",
                type: "POST",
            processData: false,
            contentType: false,
            data: data,
            success: function (result) {
                    //code after success
                    var html = "";
               // var removeIndex
                for (index = 0; index < result.result.length; ++index) {
                         removeIndex = result.result[index]; 
                        html = html + '<li class="minicart-product">' + result.result[index].HFR +;
                      
                        Html = Html + ' <a class="product-item_remove" onclick="RemoveFromCart()"></a>';
                        html = html + '<i class="ion-android-close"></i>';
                        html = html + '</a>';
                        html = html + '<div class="product-item_img">';
                        html = html + '<img src="../Content/assests/images/Catalogue/' + result.result[index].Foto + '" alt="../Content/assests/images/Catalogue/default.png">';
                        html = html + '</div>';
                        html = html + '<div class="product-item_content">';
                        html = html + '<a class="product-item_title" href="">' + result.result[index].TractorModel + " " + result.result[index].Description + '</a>';
                        html = html + '<span class="product-item_quantity">' + result.result[index].HFR + '</span>';
                        html = html + '</div>';
                        html = html + '</li>';
                    }


                $("#myCart").html(html);
                },
            error: function (er) {

                    alert(er.responseText);
                }

            });

        }

        function RemoveFromCart()
        {
            alert("Remove me")
        }
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You may check if the onclick event is triggered correctly. For example, I have an asp.net core MVC project and it has integrated Jquery by default, in my code snippet, I have an alert clause for testing if it's triggered. Code snippet is in the default home page.

    @{
    ViewData["Title"] = "Home Page";
}

<div class="text-center">
    <h1 class="display-4">Welcome</h1>
    <p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
</div>

<input id="picContent" type="file" name="photo" value="please upload a picture" />
<input id="btn1" type="button" value="upload"/>

@*@section scripts
{*@
<script>
    $("#btn1").click(function(){
        alert(1);
        return;
        var formData = new FormData();
        var img = $("#picContent")[0].files[0];
        console.log(img);
        console.log($("#picContent").val());
        formData.append("file", img);
        $.ajax({
            data: formData,
            url:"https://localhost:44340/home/upload",
            type:"post",
            data:formData,
            processData: false,
            contentType: false,
            success:function(data){
                alert(data);
            }
        })        
    })
</script>
@*}*@
about 4 years ago · Juan Pablo Isaza Relatório

0

It is html not Html.

Replace this line :

 Html = Html + ' <a class="product-item_remove" onclick="RemoveFromCart()"></a>';

with

 html = html + ' <a class="product-item_remove" onclick="RemoveFromCart()"></a>';
about 4 years ago · Juan Pablo Isaza Relatório
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