Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

169
Vistas
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.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

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.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda