Hi, I have the following problem, I need to get an image of an input and pass it to the controller; The code I use is the following: HTML:
<div class="row">
<div class="col-xs-12 col-sm-10 offset-sm-1">
<input name="Portada" type="file" id="filePicker" />
</div>
</div>
<button class="btn btn-primary btn-block" type="button" onclick="Modificar()">Guardar cambios</button>
JS:
function Modificar() {
var Portada = $('#filePicker').prop("files")[0];
var url = "@Url.Action("Modificar", "Dispositivos")";
var data = { Portada: Portada };
$.post(url, data).done(function (data) {
if (data) {
}
});
}
Controller:
public ActionResult Modificar(HttpPostedFileBase Portada)
{--- codigoControlador}
With this code it gives an error in js and does not reach the controller, if the input is null if it enters the controller. I hope you can help me.