2
I am sending a form to my Controller passing one HttpPostedFileBase
as parameter. The problem is that it always comes empty.
HTML:
<form action="@Url.Action("Import","Importacao")" method="post" class="form-horizontal">
<div class="form-group ">
<label for="fupload" id="label-fupload" class="control-label label-bordered">Clique aqui para escolher um arquivo</label>
<input type="file" id="fupload" name="fupload" class="fupload form-control border-form" onchange='getFileName()' />
</div>
<div class="form-group">
<label for="mes_referencia" class="control-label">Mês</label>
<input type="text" id="mes_referencia" name="mes_referencia" class="mes_referencia form-control" placeholder="mm/yyyy" />
</div>
<input type="submit" class="btn btn-success" id="submit" value="Enviar" style="margin-left: 200px;" />
Controller:
[HttpPost]
public ActionResult Import(HttpPostedFileBase fupload){
if (fupload != null && fupload.ContentLength > 0) {
dataset = Importador.UploadAndShow(fupload);
}
return View(dataset.Tables[0]);
}
I’ve used the parameter name
equals the Method parameter, as well as id
and class
.
Grateful!
Try placing the attribute enctype = "Multipart/form-data" in the form.
– mcamara
Read: https://stackoverflow.com/questions/4526273/what-does-enctype-multipart-form-data-mean
– novic