Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

167
Visualizações
Upload multiple files with single input Asp Mvc

I want to upload multiple files including Word Documents, Pdf and Images. I need to use a single input for files because we don't know how many files will be uploaded.

My code is this but I have problem that I can't send files to server side.

Controller Code :

public ActionResult Create([Bind(Include = "Id,Content")] Message message, IEnumerable<HttpPostedFileBase> files)
{
     if (ModelState.IsValid)
     {
         // Object save logic
         SaveFiles(message,files);
         return RedirectToAction("Index");
     }
     return View(message);
}

Part of view code :

<form name="registration"  action="">
    @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        <div class="form-group">
            <label for="Content" >Content:</label>
            <textarea class="form-control compose_content" rows="5" id="Content" name="content"></textarea>

            <div class="fileupload">
                      Attachment :  

                    <input id="files" name="files" type="file" multiple />
            </div>
        </div>
    <button type="submit" class="btn btn-default compose_btn" >Send Message</button>
</form>

I don't have problem with saving files and saving the object. only problem : files list is null.

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

I order to upload files, your form needs to include the enctype= multipart/form-data attribute.

<form name="registration"  action="" enctype= "multipart/form-data">

or better

@using (Html.BeginForm(actionName, controllerName, FormMethod.Post, new { enctype= "multipart/form-data" }))

and I strongly recommend you pass a model to the view and use the strongly typed HtmlHelper methods to create your html for the properties of your model.

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda