D
D
DarkByte20152017-02-14 13:35:25
ASP.NET
DarkByte2015, 2017-02-14 13:35:25

Why can't I send the file?

The view has this form:

@using (Html.BeginForm("Upload", "Home", FormMethod.Post))
{
    <input type="file" name="1CClientBankExchange" accept="text/plain" required />
    <input type="submit" />
}

In the controller, this action:
[HttpPost]
public ActionResult Upload(HttpPostedFile file)

Why is it not called when I send it? It doesn't give any errors either... I tried it like this:
[HttpPost]
public ActionResult Upload()
{
      var file = Request.Files["1CClientBankExchange"];
}

It doesn't help either. What is the problem?
PS I don't know if routes are needed for POST requests? Now no. But the name of the controller and action in BeginForm is also indicated there. So I don't think it's necessary...
Hurrah! I figured it out. It turns out that routes for POST requests are still needed. :D And the type of the file HttpPostedFileWrapper and the name of the variable also seem to matter (as it should be in the form).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Pavlov, 2017-02-15
@dmitry_pavlov

The example uses HttpPostedFileBase (there is some confusion about HttpPostedFile). Educational program on the topic of loading files in ASP.NET MVC.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question