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

113
Visualizações
Change src attribute for Image element after upload image in ASP.NET Core

I used upload tool for ASP.NET Core to upload person image, I put an HTML Image element beside the Upload image tool to display the image after upload it.

I invoke .Success event for upload tool and used a javascript function to set the src attribute for the image element with the uploaded image path. But unfortunately it does not work :(

This is the Image element

<img id="imgPerons" src="" width="200" height="250">

This is the javascript function:

function onSuccess(e) {
    var files = e.files[0];

    if (e.operation == "upload") {
        document.getElementById("imgPerson").src = "~/images/person_photos/image.jpeg";
    }
}

I think I have a problem with the path of the image, because I used online images like the following, and It works fine

function onSuccess(e) {
    var files = e.files[0];

    if (e.operation == "upload") {
        document.getElementById("imgPerson").src = "https://www.example.com/image.jpeg";
    }
}

What's the wrong with the path of the image?

I saved uploaded image in wwwroot/images/person_photos

The Image element and the javascript function in the path Views/Home/Index.cshtml

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Removing ~ sign in javascript code should fix the problem because it's only processed on ASP.NET Core side

document.getElementById("imgPerson").src = "/images/person_photos/image.jpeg";
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