httppostedfilebase always empty when switching to controller

Asked

Viewed 209 times

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!

  • 2

    Try placing the attribute enctype = "Multipart/form-data" in the form.

  • 1

    Read: https://stackoverflow.com/questions/4526273/what-does-enctype-multipart-form-data-mean

1 answer

3


Try placing the attribute enctype = "multipart/form-data" in form.

  • 1

    Show! It worked! I’m going to give a read on the enctype that my friend @Virgilionovic sent. Thanks :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.