0

I am trying to submit a form using jQuery. The form contains a file upload input which I have disguised using this SO method and am automatically submitting using this SO method. When I check the parameters of _upload in my controller, type has a value but file is null.

Where am I going wrong?

View:

    @using (Html.BeginForm("_upload", "Config", null, FormMethod.Post, new { @id = "form_" + Model.imageType }))
    {
        <label>
            <input id="file_@Model.imageType" type="file" name="file" required />
        </label>
            @Html.Hidden("type",Model.imageType)
    }
....
<script>
    $(function () {
        $('#file_@Model.imageType').change(function () {
            $('#form_@Model.imageType').submit();
        })
    })
</script>

Controller

    [HttpPost]
    public void _upload(HttpPostedFileBase file, string imageType) 
    { 
        //dostuff
    }
Community
  • 1
  • 1
tallpaul
  • 1,220
  • 2
  • 13
  • 35

1 Answers1

0

Change your razor/form to something like:

@using (Html.BeginForm("_upload", "Config", FormMethod.Post, new { enctype = "multipart/form-data" })){}
Mark
  • 4,773
  • 8
  • 53
  • 91