I have this input file:
Razor:
@Html.TextBox("archivo", "", new { type = "file",id = "archivo" }
Html:
<input id="archivo" name="archivo" type="file" value="">
I want to capture message if value of input is null when I press button:
<button type="button" id="btnCargarCsv" class="btn btn-primary">Cargar</button>
So on clic function I try to send message as:
$("#btnCargarCsv").on("click", function () {
if ($('#archivo').val() == null) {
$('#resultado').html('you need to select file');
}
var data = new FormData();
data.append("archivo", $("#archivo")[0].files[0]);
$.ajax({
"type": "POST",
"url": "/Configuracion/CargaCSV",
...
But it just don't throw message when input come null beacuse it don't hit:
$('#resultado').html('you need to select file');
like input is not null. What am I doing wrong?