0
$("#btn_confirmar").click(function () {
var form = new FormData(document.getElementById('formAlteraFoto'));
$.ajax({
type: 'POST',
url: '/Usuario/AlterarFoto',
data: form,
processData: false,
contentType: false,
success: function (data) {
alert('Upload com sucesso!');
},
error: function (data, jqXHR, exception) {
alert('Erro ao atualizar imgem de perfil!');
}
});
})
[HttpPost]
public ActionResult AlterarFoto()
{
//return RedirectToAction("Clientes");
if (Request.Files.Count > 0)
{
var file = Request.Files[0];
if (file != null && file.ContentLength > 0)
{
var fileName = Path.GetFileName(file.FileName);
var path = Path.Combine(Server.MapPath("~/Content/Uploads"), fileName);
file.SaveAs(path);
}
}
return RedirectToAction("EditarCliente");
}
Include your view code or redenrized html from it.
– Leandro Angelo
You must return the name (or path) of the image saved in
data
and change with$(id ou classe da imagem).attr("src", data);
– Sam
How so bro ? Could you show me ? Don’t manjo mt de Ajax. :(
– S. Santos