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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T13:14:43+00:00 2026-05-19T13:14:43+00:00

I have a form upload that works but I would like to pass model

  • 0

I have a form upload that works but I would like to pass model information for my database to save the file with a different name of course.

Here is my Razor view:

@model CertispecWeb.Models.Container

@{
  ViewBag.Title = "AddDocuments";
}

<h2>AddDocuments</h2>

@Model.ContainerNo

@using (Html.BeginForm("Uploadfile", "Containers", FormMethod.Post, 
            new { enctype = "multipart/form-data" }))
{
    <input type='file' name='file' id='file' />
    <input type="submit" value="submit" />
}

Here is my Controller:

[HttpPost]
public ActionResult Uploadfile(Container containers, HttpPostedFileBase file)
{
     if (file.ContentLength > 0)
     {
        var fileName = Path.GetFileName(file.FileName);
        var path = Path.Combine(Server.MapPath("~/App_Data/Uploads"),
                       containers.ContainerNo);
        file.SaveAs(path);
     }

     return RedirectToAction("Index");
}

The model information is not passed through to the controller. I have read that I might need to update the model, how would I do 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-19T13:14:44+00:00Added an answer on May 19, 2026 at 1:14 pm

    Your form doesn’t contain any input tag other than the file so in your controller action you cannot expect to get anything else than the uploaded file (that’s all that’s being sent to the server). One way to achieve this would be to include a hidden tag containing the id of the model which will allow you to retrieve it from your datastore inside the controller action you are posting to (use this if the user is not supposed to modify the model but simply attach a file):

    @using (Html.BeginForm("Uploadfile", "Containers", FormMethod.Post, new { enctype = "multipart/form-data" }))
    {
        @Html.HiddenFor(x => x.Id)
        <input type="file" name="file" id="file" />
        <input type="submit" value="submit" />
    }
    

    and then in your controller action:

    [HttpPost]
    public ActionResult Uploadfile(int id, HttpPostedFileBase file)
    {
        Containers containers = Repository.GetContainers(id);
        ...
    }
    

    On the other hand if you wanted to allow the user to modify this model then you will need to include the proper input fields for each field of your model that you want to be sent to the server:

    @using (Html.BeginForm("Uploadfile", "Containers", FormMethod.Post, new { enctype = "multipart/form-data" }))
    {
        @Html.TextBoxFor(x => x.Prop1)
        @Html.TextBoxFor(x => x.Prop2)
        @Html.TextBoxFor(x => x.Prop3)
        <input type="file" name="file" id="file" />
        <input type="submit" value="submit" />
    }
    

    and then you will have the default model binder reconstruct this model from the request:

    [HttpPost]
    public ActionResult Uploadfile(Container containers, HttpPostedFileBase file)
    {
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a file upload script that works [finally] but want to have users
I have a method set up that uses jquery form for a file upload
I have a form that I would like to submit to a component for
I have an upload form that takes a user about 30 min. to complete.
I am new to Jquery. I have an upload form that when something is
I have a following problem, I have HTML form that uploads a file with
I have an upload form with a file to be uploaded. The issue I
I have created a form to upload a a newsletter into the database. I'm
Let's say that I have a file (file1.php) with a simple form with the
I would like to upload different types of files pressumably pdfs to a certain

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.