Reputation: 587
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)
{ }
Upvotes: 3
Views: 3562
Reputation: 48415
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.
Upvotes: 3