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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:04:00+00:00 2026-06-13T08:04:00+00:00

I have an ASP.NET MVC Website that has a dropdown list that is being

  • 0

I have an ASP.NET MVC Website that has a dropdown list that is being created using this in the view…

@Html.DropDownList("Programs")

Programs is populated from a Business Object collection and stuffed into the ViewBag in the index action on the Home Controller…

\\get items...
ViewBag.Programs = items;

The view also has potentially three files I am getting like this in the same view…

<input type="file" name="files" id="txtUploadPlayer" size="40" />  
<input type="file" name="files" id="txtUploadCoaches" size="40" />  
<input type="file" name="files" id="txtUploadVolunteers" size="40" /> 

All of the aforementioned controls are contained in a Form that is created in the view using…

@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
     <!--  file and other input types  -->
     <input type="submit" name="btnSubmit" value="Import Data" />
}

My problems is that I cannot find a way to process all of the files AND reference the form fields.

Specifically, I need to know what Program the user selected from the dropdown.

I can process the files using this code with no problem…

[HttpPost]
public ActionResult Index(IEnumerable<HttpPostedFileBase> files)
//public ActionResult Index(FormCollection form)
{

    _tmpFilePath = Server.MapPath("~/App_Data/uploads");

    if (files == null) return RedirectToAction("Index");
    foreach (var file in files)
    {
        if (file != null && file.ContentLength > 0)
        {
            var fileName = Path.GetFileName(file.FileName);
            var path = Path.Combine(_tmpFilePath, fileName);
            if (System.IO.File.Exists(path)) System.IO.File.Delete(path);

            _file = file;

            file.SaveAs(path);

            break;  //just use the first file that was not null.
        }
    }



    //SelectedProgramId = 0;

    //DoImport();

    return RedirectToAction("Index");
}

But I cannot figure how to ALSO get access to the POST form values especially the Programs dropdown selected value (and for the record there is also a checkbox that I cannot read the value from.) Fiddler shows me that the Response has the file references AND the selected program but I cannot figure out how to get them out of the POST using ASP.NET MVC.

I know this question is pretty basic but I am stilling learning the whole web/http thing not just MVC.

EDIT
Thanks for your answers. I had the thought that the answer might lie in passing in both the files and the form values into the POST.

So my last question is … how do I change the HTML.BeginForm block to pass in both the files and form values? Right now I have …

@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
  //do stuff
}

What should that using statement be to get both form values and files as separate parameters of the ActionResult?

EDIT MY EDIT
It seems that I don’t have to make any changes…the debugger is showing that both files and form are non-null. Cool! Is that right?

  • 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-06-13T08:04:01+00:00Added an answer on June 13, 2026 at 8:04 am

    I think that this should do it

    [HttpPost]
    public ActionResult Index(IEnumerable<HttpPostedFileBase> files, FormCollection form)
    {
      //handle the files
    
      //handle the returned form values in the form collection
    }
    

    You should be able to pass in 2 parameters in the [HttpPost] action. you can also pass in the HTML name.

    Edit: I also had problems with forms in ASP.net. I suggest looking into this blog post by Scott Allen.
    http://odetocode.com/blogs/scott/archive/2009/04/27/6-tips-for-asp-net-mvc-model-binding.aspx

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

Sidebar

Related Questions

I have the following view definition in my asp.net mvc website: <% Using Ajax.BeginForm(UsrCtlChangePassword,
I have an ASP.NET MVC website which has a particular javascript file that needs
Hi, I have built a ASP.NET MVC website that uses Membership, this works fine.
I have an Asp.Net Mvc website that has a listing controller. The route looks
In my asp.net-mvc website I have a field that usually has a string (from
I have an ASP.NET MVC website that works in tandem with a Windows Service
I have an asp.net mvc website that returns a JSON result to certain pages
I have an ASP.NET MVC 3 website that works perfectly in IIS7 integrated mode.
I have built an ASP.NET MVC 2 website that I am hosting with Rackspace
I have an asp.net mvc website which of course has a web.config file. 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.