Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upload of two different files, from two different inputs

I'm currently trying to handle the upload of two different files from two different <input type="file"/>s.

For example:

@using (Html.BeginForm("AddIssue", "Magazine", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<fieldset>
        <div class="editor-field">
            <div class="editor-label">Issue: </div>
            <input type="file" name="issueFile" id="issueFile"/>
        </div>
        <div class="editor-field">
            <div class="editor-label">Cover: </div>
            <input type="file" name="issueCover" id="issueCover"/>
        </div>
        <button type="submit">Save</button>
    </fieldset>
}

I've figured out how to receive a file (or files) from one input, but can't find any appropriate information on how to receive files from multiple inputs.

I already have a method for POST, but can't figure out what shall I receive on post.

[HttpPost, Authorize]
public ActionResult AddIssue(string dummy)
{ }
like image 558
Kamilius Avatar asked Nov 19 '25 17:11

Kamilius


1 Answers

After the comment, here is a more specific solution...

You need to ensure that your Controller Action parameters are named the same as the name attribute on your form fields. This should work for you:

public ActionResult AddIssue(HttpPostedFileBase issueFile, HttpPostedFileBase issueCover)
{ }

Remember, it is the name attributes that are used to identify the fields from the controller. The id attributes mean nothing, and do not have to match.

like image 91
musefan Avatar answered Nov 21 '25 08:11

musefan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!