Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Simon Andersson 6 posts 27 karma points
    Jul 30, 2014 @ 15:52
    Simon Andersson
    0

    Store <input type="file"/> in model, always getting null.

    Hey,

    This start to driving me crazy. I'm creating a HTML form where I want to upload files (multiple) through this form with a <input type="file" multiple />. Problem is that the file(s) is never sent to the model so the property always holding null instead of the uploaded file when the form is posted.

    In my view:

    <div class="form-group margin_clear">
                <label class="control-label col-md-2" for="ImageList">Image upload:*</label>
    
                <div class="input-group col-md-4">
                    <span class="input-group-btn">
                        <span class="btn btn-primary btn-file">
                            Browse @Html.TextBoxFor(model => model.ImageList, new { @type = "file", @multiple = "multiple" })
                        </span>
                    </span>
                    <input type="text" class="form-control" readonly>
                </div>
                @Html.ValidationMessageFor(model => model.ImageList, null, new { @class = "alert alert-danger imagelist-validation" })
    
            </div>

    In my model:

    public IEnumerable<HttpPostedFileBase> ImageList { get; set; }

    Any idea of how to get this to work? Everything works except for this file upload.

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Jul 31, 2014 @ 12:50
    Jeroen Breuer
    0

    What does the input field looks like? Instead of the Html.TextBoxFor helper just try to write it like this:

    <input type="file" name="ImageList" multiple />

    Jeroen

  • Simon Andersson 6 posts 27 karma points
    Jul 31, 2014 @ 12:59
    Simon Andersson
    1

    I actually solved this problem. Files were never posted because I used Ajax.BeginForm to build the form instead of Html.BeginForm.

Please Sign in or register to post replies

Write your reply to:

Draft