1
I need to call Actionresult each time I select a new record in the Dropdownlist calling only 1 time when loading the page.
No Controller
private string PegarCaminhoImagem(Int16 controle)
{
sistema_mobileEntities dao = new sistema_mobileEntities();
dao.fotos.Find(controle);
var caminho = dao.fotos.First().Foto;
return caminho;
}
public ActionResult AtualizaFoto(Int16 caminhofoto)
{
int largura = 100;
int altura = 100;
String CaminhoFoto = "";
try
{
CaminhoFoto = PegarCaminhoImagem(caminhofoto);
var webImagem = new WebImage(@CaminhoFoto).Resize(largura, altura, false, false);
return File(webImagem.GetBytes(), @CaminhoFoto);
}
catch (Exception ex)
{
return Json("A Imagem não existe : " + ex.Message);
}
}
Na Views:
@model ProjetoDelphiMobile.Models.cliente
@{
ViewBag.Title = "";
}
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script>
$(document).ready(function () {
$("#idFoto").on("change", function () {
var srcRecebe = $($(this)).val();
if (srcRecebe > 0) {
$.post("/ConsultaCliente/AtualizaFoto", { caminhofoto: srcRecebe }).done(function (data) {
$('#caminho').attr("src", data);
})
}
});
});
</script>
<form>
<fieldset data-role="controlgroup">
<label>Foto:</label>
<div id="selecao">
@Html.DropDownList("idFoto", String.Empty)
</div>
<div >
<img id="foto" src="@Url.Action("AtualizaFoto", "ConsultaCliente", new {caminhofoto = "caminho" })" alt="thumbnail" />
</div>
<br />
<label>Nome:</label>
@Html.TextBoxFor(model => model.nome, new { disabled = false })
<label>Nome:</label>
@Html.TextBoxFor(model => model.nome, new { disabled = false })
<label>Nome do pai:</label>
@Html.TextBoxFor(model => model.pai, new { disabled = false })
<label>Nome da Mãe:</label>
@Html.TextBoxFor(model => model.mae, new { disabled = false })
<label>Data de Nascimento:</label>
@Html.TextBoxFor(model => model.datanascimento, new { disabled = false })
<ul data-role="listview" data-inset="true" data-divider-theme="e">
<li><a href="/ConsultaCliente">Retornar para consulta</a></li>
</ul>
</fieldset>
</form>
Could you explain your problem better? Unable to access Actionresult? Unable to return data?
– Hermes Autran
The problem is that it is calling only 1 time when it loads the page.
– Harry
When you change Select, does it only search 1 time? In a new attempt it does not search in Action!?
– Hermes Autran
Yes, just call once, I want to call whenever I select new information
– Harry