Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6836861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:24:24+00:00 2026-05-26T23:24:24+00:00

I need some help. I’m trying to upload files using <input type=file> . Here

  • 0

I need some help. I’m trying to upload files using <input type="file">. Here is my View:

@using (Html.BeginForm("BookAdd", "Admin", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    <input type="file" name="files[0]" id="files[0]" />
    <input type="file" name="files[1]" id="files[1]" />
    <input type="submit" value="Upload Book" />
}

And here is an Action which should process uploaded file.

[HttpPost]
public ActionResult BookAdd(IEnumerable<HttpPostedFileBase> files)
{
    // some actions
    return View();
}

The problem is that “files” always contains two elements which are null.
What can be done to fix it?

It’s time for some news. It seems like I found the problem, but I still don’t know how to fix it. It appears that despite the fact I’m using “multipart/form-data” here:

@using (Html.BeginForm("BookAdd", "Admin", FormMethod.Post, new { enctype="multipart/form-data" }))
{
    <input type="file" name="File" id="file1" />
    <input type="file" name="File" id="file2" />
    <input type="submit" value="Upload Book" />
}

Request.ContentType remains “application/x-www-forum-urlencoded” in controller..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:24:25+00:00Added an answer on May 26, 2026 at 11:24 pm

    Just get rid of the square brackets in the names of your input fields:

    @using (Html.BeginForm("BookAdd", "Admin", FormMethod.Post, new { enctype = "multipart/form-data" }))
    {
        <input type="file" name="files" id="file1" />
        <input type="file" name="files" id="file2" />
        <input type="submit" value="Upload Book" />
    }
    

    UPDATE:

    After looking at the sample project you sent me the problem is that you have 2 nested forms. This is not allowed in HTML. You have one form in your _Layout.cshtml and another form in your BookAdd.cshtml view. That’s the reason why despite the enctype="multipart/form-data" attribute on your inner form you were getting the wrong Request.ContentType. So you will have to unnest those forms if you want this to work. Also in the example you sent me your BookAdd controller action doesn’t have the correct signature taking a list of files, but I guess that’s due to some tests you were doing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some help in using the NSURLCache to download a simple file. It
I need some help figuring out what I'm doing wrong here. I am trying
I need some help calculating Pi. I am trying to write a python program
Need some help with what is probably a pretty basic SQL query. I'm trying
need some help! I'm trying to write some code in objective-c that requires part-of-speech
I need some help - I am trying to use a custom validation attribute
I need some help trying to come up with a way to set this
Need some help with putting this query together. I'm using Mysql I have two
I need some help. I have been searching for days trying to find solution
Need some help for creating a File and String search engine. The program needs

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.