$("#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");
}