Doubt Insert Image with Jquery?

Asked

Viewed 1,029 times

1

Friends,

Following the posted examples, I made the adjustments:

        public ActionResult ThumbNail(int largura, int altura, string caminhofoto)
    {
        if (caminhofoto != "caminho" )
        {
            WebImage webImagem = new WebImage(@caminhofoto).Resize(largura, altura, false, false);
            return File(webImagem.GetBytes(), @caminhofoto);
        }
        return View();
    }

This Actionresult above needs to receive Jquery:

<script >

    function BuscarCaminho()
    {
        //Pega o elemento 'select'
        var select = document.getElementById("selecao");
        //Altera o valor do atributo 'src' da imagem para carregar a imagem selecionada
        if (select != "") {
            document.getElementById('caminho').src = select.value;
          //  alert(select.value);
        }
    }

This is the Altered Jquery, I’m passing the photo path:

        <div >
        <img id="foto" src="@Url.Action("Thumbnail", "ConsultaCliente", new {caminhofoto = "caminho", largura = 100, altura = 100 })" alt="thumbnail" />
    </div>


        <label>Foto:</label>
        <div id="selecao" onchange="BuscarCaminho()" >
            @Html.DropDownList("idFoto", String.Empty)
         </div>

At this point, for each selected photo I want to send the image to be viewed on the screen. thanks

  • I don’t quite understand what you really want to do.

  • the onchange is in a div, and should be in the select. Maybe in that case it would be better to use html even instead of the syntax razor.

  • Take a look at my answer. If you do not satisfy your need comment that I will modify to try to fit better in what you want to do. for now with your question was what to do according to what I understood.

1 answer

1

Try to change your javascript for something like:

<script>
    function BuscarCaminho()
    {
        //Pega o elemento 'select'
        var select = document.getElementById("selecao");
        //Altera o valor do atributo 'src' da imagem para carregar a imagem selecionada
        document.getElementById('foto').src = select.value;
        //alert(select.value);
    }
</script>

And his HTML for something like this:

<label>Foto:</label>
<div>
    <select id="selecao" onchange="BuscarCaminho()">
        <option value="caminho_da_foto1">nome_da_foto1</option>
        <option value="caminho_da_foto2">nome_da_foto2</option>
        <option value="caminho_da_foto3">nome_da_foto3</option>
    </select>
</div>
<div>
    <img id="foto" src="@Url.Action("Thumbnail", "ConsultaCliente", new {caminhofoto = teste, largura = 100, altura = 100 })" alt="thumbnail" />
</div>
  • Friend, thank you, but the path of the photo comes from : <div id="selects" onchange="Searchpath()"> @Html.Dropdownlist("idFoto", String.Empty) </div>

  • I need to pass like this: <div > <img id="photo" src="@Url.Action("Thumbnail", "Client query", new {camiofoto = camioaqui, width = 100, height = 100 })" alt="thumbnail" /> </div>

  • the problem is that the div will not launch the onchange by changing the select. Explain a little better why you "have" to do so.

  • I changed the question, adjusting the code according to what you sent me, see if you can help.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.