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

  • SEARCH
  • Home
  • 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 6196367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:37:49+00:00 2026-05-24T03:37:49+00:00

There are similar posts out there but they do not seem to represent my

  • 0

There are similar posts out there but they do not seem to represent my situation. Apologies in advance if this is a re-post.

I have my view as

@FileUpload.GetHtml(initialNumberOfFiles:1,allowMoreFilesToBeAdded:true,includeFormTag:true, uploadText: "Upload" )

@model IEnumerable<EpubsLibrary.Models.Partner>
@{ using (Html.BeginForm("Index","Epub")) 
   {
        @Html.DropDownList("PartnerID", (IEnumerable<SelectListItem>)ViewBag.Partners, "None")
        <input type="submit" value="send" id="pickPartner" hidden="hidden"/>
   }        
}

<script type="text/javascript">
    $(".file-upload-buttons input").click(function () {
        $("#pickPartner").click();
    });
</script>

my controller is

[HttpPost]
public ActionResult Index(IEnumerable<HttpPostedFileBase> fileUpload, FormCollection collection)
{
    int selectedPartner, count =0;
    //int selectedPartner = int.Parse(collection["PartnerID"]);
    if(!int.TryParse(collection["PartnerID"], out selectedPartner))
    {
        selectedPartner = 0;
        ModelState.AddModelError("", "You must pick a publishing agency");
    }
    IList<Partner> p = r.ListPartners();
    ViewBag.Partners = new SelectList(p.AsEnumerable(), "PartnerID", "Name", selectedPartner);

    //make sure files were selected for upload 
    if (fileUpload != null)
    {
        for (int i = 0; i < fileUpload.Count(); i++)
        {
            //make sure every file selected != null
            if (fileUpload.ElementAt(i) != null)
            {
                count++;
                var file = fileUpload.ElementAt(i);
                if (file.ContentLength > 0)
                {
                    var fileName = Path.GetFileName(file.FileName);
                    // need to modify this for saving the files to the server
                    var path = Path.Combine(Server.MapPath("/App_Data/uploads"), Guid.NewGuid() + "-" + fileName);
                    file.SaveAs(path);
                }
            }
        }
    }

    if (count == 0)
    {
        ModelState.AddModelError("", "You must upload at least one file!");
    }
    return View();
}

I am using the file upload helper from Microsoft Web Helpers to upload files. The problem I am having is the helper created a form and I have another form I need to submit data from as well on the same page.

I thought I could link the submit buttons so that when you click upload it also sent the other form data but the data is not being sent. Each form works independently of the other with no issue but I need them to work together. Any advice would be appreciated.

Ok I updated the view with

@model IEnumerable<EpubsLibrary.Models.Partner>
@{ using (Html.BeginForm("Index","Epub")) 
   {
        @Html.DropDownList("PartnerID", (IEnumerable<SelectListItem>)ViewBag.Partners, "None")
        @FileUpload.GetHtml(initialNumberOfFiles: 1, allowMoreFilesToBeAdded: true, includeFormTag: false, uploadText: "Upload")
        <input type="submit" value="send" id="pickPartner"/>
   }        
}

But now the file data does not seem to be getting passed anymore.

— Update —

I have made the following changes.
The view now looks like

@model IEnumerable<EpubsLibrary.Models.Partner>
@{ using (Html.BeginForm("Index", "Epub", new { enctype = "multipart/form-data" }))
   {
        @Html.DropDownList("PartnerID", (IEnumerable<SelectListItem>)ViewBag.Partners, "None")
        @FileUpload.GetHtml(initialNumberOfFiles: 1, allowMoreFilesToBeAdded: true, includeFormTag: false, uploadText: "Upload")
        <input type="submit" value="send" id="pickPartner"/>
   }        
}

and the controller

[HttpPost]
        public ActionResult Index(IEnumerable<HttpPostedFileBase> fileUpload, int PartnerID = 0)
        //public ActionResult Index(IEnumerable<HttpPostedFileBase> fileUpload, FormCollection collection)
        {
            int count =0;
            IList<Partner> p = r.ListPartners();
            ViewBag.Partners = new SelectList(p.AsEnumerable(), "PartnerID", "Name", PartnerID);
            //make sure files were selected for upload 
            if (fileUpload != null)
            {
                for (int i = 0; i < fileUpload.Count(); i++)
                {
                    //make sure every file selected != null
                    if (fileUpload.ElementAt(i) != null)
                    {
                        count++;
                        var file = fileUpload.ElementAt(i);
                        if (file.ContentLength > 0)
                        {
                            var fileName = Path.GetFileName(file.FileName);
                            // need to modify this for saving the files to the server
                            var path = Path.Combine(Server.MapPath("/App_Data/uploads"), Guid.NewGuid() + "-" + fileName);
                            file.SaveAs(path);
                        }
                    }
                }
            }

            if (count == 0)
            {
                ModelState.AddModelError("", "You must upload at least one file!");
            }
            return View();
        }
    }

I am trying to figure out how the file data is getting sent over in the post (if it is) so I can save the files.

— Final Update with Answer —

Well the problem turned out to be two fold.. 1st the issue with @FileUpload and needing to set includeFormTag: false

The other problem I discovered was I needed to make sure in my @Html.BeginForm I included FormMethod.Post This was discovered when the fileUpload count kept coming back as 0. I ran the profiler on firebug and it pointed out that the file data was not actually getting posted. Here is the corrected code below.

my view

@model IEnumerable<EpubsLibrary.Models.Partner>
@{ using (Html.BeginForm("Index", "Epub", FormMethod.Post, new { enctype = "multipart/form-data" }))
   {
        @Html.DropDownList("PartnerID", (IEnumerable<SelectListItem>)ViewBag.Partners, "None")
        @FileUpload.GetHtml(initialNumberOfFiles: 1, allowMoreFilesToBeAdded: true, includeFormTag: false, uploadText: "Upload")
        <input type="submit" value="send" id="pickPartner"/>
   }        
} 

my controller

[HttpPost]
public ActionResult Index(IEnumerable<HttpPostedFileBase> fileUpload, int PartnerID = 0)        
{
    int count =0;
    IList<Partner> p = r.ListPartners();
    ViewBag.Partners = new SelectList(p.AsEnumerable(), "PartnerID", "Name", PartnerID);
    //make sure files were selected for upload 
    if (fileUpload != null)
    {
        for (int i = 0; i < fileUpload.Count(); i++)
        {
            //make sure every file selected != null
            if (fileUpload.ElementAt(i) != null)
            {
                count++;
                var file = fileUpload.ElementAt(i);
                if (file.ContentLength > 0)
                {
                    var fileName = Path.GetFileName(file.FileName);
                    // need to modify this for saving the files to the server
                    var path = Path.Combine(Server.MapPath("/App_Data/uploads"), Guid.NewGuid() + "-" + fileName);
                    file.SaveAs(path);
                }
            }
        }
    }

    if (count == 0)
    {
        ModelState.AddModelError("", "You must upload at least one file!");
    }
    return View();
}

Thank you @Jay and @Vasile Bujac for your help with this.

  • 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-24T03:37:50+00:00Added an answer on May 24, 2026 at 3:37 am

    Set IncludeFormTag to false and put it inside your other form using.

    @model IEnumerable<EpubsLibrary.Models.Partner>
    @{ using (Html.BeginForm("Index","Epub")) 
       {
            @FileUpload.GetHtml(initialNumberOfFiles:1,allowMoreFilesToBeAdded:true,includeFormTag:false, uploadText: "Upload" )
    
            @Html.DropDownList("PartnerID", (IEnumerable<SelectListItem>)ViewBag.Partners, "None")
            <input type="submit" value="send" id="pickPartner" hidden="hidden"/>
       }        
    }
    

    Update:
    Try changing the signature of your view to this:

    public ActionResult Index(IEnumerable<HttpPostedFileBase> fileUpload, int PartnerID = 0)
    

    Check the overloads for FileUpload.GetHtml and see if there is a parameter to set the field name for your file uploads. Previously it was just the files being uploaded, now its files and a parameter, so naming becomes more important.

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

Sidebar

Related Questions

I realize there are similar posts to this out there, but rest assured, this
I checked out a post similar to this but the linkage was different the
I quickly searched for this before posting, but could not find any similar posts.
I realize that there are other posts asking similar questions, but do not quite
I have seen a few questions similar to this around but could not figure
Is there an alternative ActionScript 3 lightweight framework out there similar to Flex, but
There are similar questions to this, but I don't think anyone has asked this
There are similar questions out there on this topic, such as When can I
This site is pretty good but I'm wondering what other resources are out there.
I know there is more than one question out there that matches this, but

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.