<input type="file" receiving only null value

Asked

Viewed 78 times

0

I’m having difficulty my project, I have a field in my form where I pass a file to it and send to my controller, problem is that the value always arrives null, I tried several ways but, I’m not finding my mistake, could give me a force.

my view

@model WebApplication11.Models.Remessa

@{
    ViewBag.Title = "Index";
}
<h2>Upload de Arquivos</h2>
@using (Html.BeginForm("Index", "Candidato", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    <div class="well">
        <table class="table table-striped">
            <tr>
                <td>Arquivo : </td>
                <td><input type="file" asp-for="Arquivo" name="arq" multiple /></td>
            </tr>
            <tr>
                <td>&nbsp;</td>
                <td><input type="submit" name="submit" value="Enviar Arquivo" /></td>
            </tr>
            <tr>
                <td>@ViewBag.Mensagem</td>
            </tr>
        </table>
    </div>
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;


namespace WebApplication11.Models
{
    public class Remessa
    {
        public HttpPostedFileBase Arquivo { get; set; }
    }
}

 [HttpPost]
    public ActionResult Index(Remessa arq)
    {
        try
        {
            string nomeArquivo = "";
            string arquivoEnviados = "";

                if (arq.Arquivo.ContentLength > 0)
                {
                    nomeArquivo = Path.GetFileName(arq.Arquivo.FileName);
                    var caminho = Path.Combine("~/Imagens", nomeArquivo);
                arq.Arquivo.SaveAs(caminho);
                }

                arquivoEnviados = arquivoEnviados + " , " + nomeArquivo;

            ViewBag.Mensagem = "Arquivos enviados  : " + arquivoEnviados + " , com sucesso.";
        }
        catch (Exception ex)
        {
            ViewBag.Mensagem = "Erro : " + ex.Message;
        }
        return View();
    }
  • The way you did you will probably find your file inside Request.Files

  • Hello Hello, thank you for your attention but when I put Resquest.Files error arose saying that Httprequest does not contain a definition for files =/....

  • 1

    I do not mean httprequest, but httpcontext.request -> https://docs.microsoft.com/pt-br/dotnet/api/system.web.httpcontext.request?view=netframework-4.8

No answers

Browser other questions tagged

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