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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:51:52+00:00 2026-05-16T14:51:52+00:00

I am trying to go to a view with a speicifed batchId parameter wrapped

  • 0

I am trying to go to a view with a speicifed batchId parameter wrapped in a ViewModel, pick a file to upload, get the uploaded file back and store the file data w/ the associated BatchId value in a database.

When the form is submitted I don’t know how to get back the viewmodel and the PostedFileBase so that I can get the BatchId value.

I need the batchId value to associate it with the data I am storing in the database.

I have the following Action Method in my Controller to allow adding new customers to the specified batch by means of a file upload and import:

public ActionResult AddCustomers(int batchId)
{
    var viewModel = new AddCustomersViewModel() { BatchId = batchId, //other view model properties };
        return View(viewModel);
}

My view is strongly typed to that ViewModel:

Inherits="System.Web.Mvc.ViewPage<TestExcelImport.Areas.Admin.ViewModels.AddCustomersViewModel>

and has the following for the file upload:

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h2>AddCustomers  Batch ID : <%:Model.BatchId %></h2>

    <form action="/Admin/Dashboard/AddCustomers" enctype="multipart/form-data" method="post">
        <input type="file" id="SourceFile" name="SourceFile" />
        <br />
        <input type="submit" value="Send" name="btnUpload" id="Submit1" />
    </form>

</asp:Content> 

My HttpPost Action Method is defined as:

    [HttpPost]
    public ActionResult AddCustomers(HttpPostedFileBase SourceFile)
    {
        //int batchId = ??? HOW DO I Get the BatchId

            int fileLength = SourceFile.ContentLength; //works!
            // read through SourceFile.InputStream and store it in db
        //need the associated BatchID though    

         return RedirectToAction("Index");
    }

I have tried adding a AddCustomersViewModel in the HttpPost return method parameter list but it is always null. I can read/parse the uploaded file just fine, just can’t get back which BatchId it was a part of.

Anybody see what I’m doing wrong?

Thanks

  • 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-16T14:51:53+00:00Added an answer on May 16, 2026 at 2:51 pm

    While there are a number of ways to achieve what you want, I would recomend something like the following (since it’s the simplest):

    Change your action method signature to:

    public ActionResult AddCustomers(int BatchID, HttpPostedFileBase SourceFile) 
    

    And change the rendered view to:

    <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
        <h2>AddCustomers  Batch ID : <%:Model.BatchId %></h2>
    
        <form action="/Admin/Dashboard/AddCustomers" enctype="multipart/form-data" method="post">
            <input type="hidden" value="<%: Model.BatchId %>" id="BatchID" name="BatchID" />
            <input type="file" id="SourceFile" name="SourceFile" />
            <br />
            <input type="submit" value="Send" name="btnUpload" id="Submit1" />
        </form>
    
    </asp:Content>
    

    This ensures that your BatchId value gets round-tripped along with the file.

    More advanced solutions (if this does not fit your needs) could include:

    • adding the BatchId in the URL that the form gets posted to.
    • using Session state to store the id.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to create a list to return some JSON data to a view. Following
Not that I'm trying to prevent 'View Source' or anything silly like that, but
I am trying to access a view inside a splitter from my mainframe. At
I'm trying to create a master detail view of a linq to sql relationship
I am trying to make a search view in Django. It is a search
I'm trying to add a strongly-typed view to the sample app that's created when
I am trying to create a view for a UNION of 2 select statements
I am trying to write a view that will generate a report which displays
I am trying to determine why an asp.net grid view is so horribly slow.
I am trying to pass an XML list to a view but I am

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.