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 888223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:21:39+00:00 2026-05-15T13:21:39+00:00

I have set the enctype to: multipart/form-data yet whenever I submit this form, the

  • 0

I have set the enctype to: multipart/form-data yet whenever I submit this form, the Request.ContentType is: application/x-www-form-urlencoded and the contents of the upload can’t be retrieved from Request.Files.

Here is my View:

    <% using (Html.BeginForm("Import", "Content", FormMethod.Post, new { enctype = "multipart/form-data" })) { %>

<p>
    <%= Html.CheckBox("DeleteExisting")%> Delete Existing Records?
</p>   

<p>
    <input type="file" name="FileUpload" id="FileUpload" /> Select a dump file.
</p>

<p>
    <input type="submit" value="Import Now" />
</p>

<% } %>

Here is my Action:

        [HttpPost]
    public ActionResult Import(FormCollection fc)
    {
        string chkDelete = fc["DeleteExisting"];
        //string filename = fc["FileUpload"];

        if (!chkDelete.Equals("false"))
        {
            //TODO: delete existing records, if specified
        }


        var inputFile = Request.Files["FileUpload"];


        return View();
    }

In the PostBack, the “fc” variable is filled and I can access the checkbox’s value and can get the filename of the upload.

Why would my enctype be ignored?

I have tried manually putting the form tag in the view with the attributes in different positions, but that made no difference.

The only thing I can think is that this Import form is nested within the MasterPage’s form, but that doesn’t seem like it should be a problem. Plus I have this form enclosed properly.

Any suggestions?

  • 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-15T13:21:40+00:00Added an answer on May 15, 2026 at 1:21 pm

    I believe there are two issues at play here:

    The only thing I can think is that this Import form is nested within the MasterPage’s form, but that doesn’t seem like it should be a problem. Plus I have this form enclosed properly.

    This is probably most of the problem – there are two things that worry me:

    1. Nested forms are not legal (X)HTML – the browser is quite legitimately allowed to ignore the second form declaration, and close the form at the first form tag it comes to – so that could well be the problem you’re seeing.
    2. As we’re dealing with ASP.NET MVC, there’s no reason at all to have one big enclosing form in the master page, that’s just going to get in the way (like we’re possibly seeing here).

    I recommend that you remove the form from the master page and just add them in when you need them around an actual form. That may well solve the problem you’re seeing as well.

    Secondly, you’ll need to add a parameter based on the HttpPostedFileBase to your action:

    public ActionResult Import(FormCollection fc, HttpPostedFileWrapper FileUpload)
    {
      string chkDelete = fc["DeleteExisting"];
    
      if (null != FileUpload && 0 < FileUpload.ContentLength) {
       // We have an upload.
    
       string filename = FileUpload.FileName;
    
        if (!chkDelete.Equals("false"))
        {
            //TODO: delete existing records, if specified
        }
    
        // Stream file in from FileUpload.InputStream e.g.:
        var bytesOriginal = new byte[FileUpload.ContentLength];
        FileUpload.InputStream.Read(bytesOriginal, 0, FileUpload.ContentLength);
    
        //Read from the byte array as you would any normal file.
      }
    
      return View();
    }
    

    I’ve just tried this in a simple view (no master page, no nested forms) and it behaved exactly as I’d expect – without the HttpPostedFileWrapper the FormCollection only contained the checkbox.

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

Sidebar

Related Questions

I have this form: <form method=post enctype=multipart/form-data accept-charset=UTF-8> But when I submit an é
This is my markup: <form action=/Customer/Create enctype=multipart/form-data method=post> <input id=file type=file style=width:300px /> <input
I'm having a slight problem. I have set my <input type=file> to onChange=this.form.submit() .
I've got a simple upload form. Here's my code: <form id=Form1 method=post enctype=multipart/form-data runat=server
I have set up a Django application that uses images. I think I have
This is strange, but I have a web form in one of my sites
I have a form for uploading image. The index.html submits data to resizer.php. The
I have my html5 form working to upload multiple mp3 files with one submit
We have set up a system where notifications get sent to a user with
I have set a canvas' background to an image of a company logo. I

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.