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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:29:30+00:00 2026-06-17T04:29:30+00:00

Hi I seem to be having a problem when posting images.I have checked many

  • 0

Hi I seem to be having a problem when posting images.I have checked many questions on stackoverflow and on other forums that discuss this topic but none seem to provide the answer I need.Here is my code:

@using( Html.BeginForm("Create", "ProductManager", FormMethod.Post, new{enctype = "multipart/form-data"})){

    <ul>
        ....
        <li>
             @Html.LabelFor(model => model.ProductImagePath , "Avatar")
             <input type="file" id="ProductAvatar" name="ProductAvatar" />
             @Html.HiddenFor(model => model.ProductImagePath , new { id = "AvatarHiddenField"})
        </li>
         <li>
             @Html.LabelFor(model => model.ProductName , "Product Name")
             @Html.EditorFor(model => model.ProductName)
         </li>
         .....
    </ul>
}
[HttpPost]
        public ActionResult Create( FormCollection collection ,  HttpPostedFileBase avatar)
        {
            string file = collection["ProductAvatar"];
            var avatars = avatar;
        }

From debugging I found that HttpPostedFileBase returns null.The other form data in the collection gets posted succesfully.Only the image does not get posted.I can not seem to acces ProductAvatar from either the FormCollection or the HttpPostedFileBase , it seems like it’s not even posted

How can I corect this problem?

  • 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-17T04:29:31+00:00Added an answer on June 17, 2026 at 4:29 am

    You have to use change the name of your HttpPostedFile parameter to the same name of your input file on the form, or you also can use Request.Files and get by the by the name attribute of your input file, try something like this:

    [HttpPost]
    public ActionResult Create(FormCollection collection)
    {
       HttpPostedFileBase file = Request.Files["ProductAvatar"];
    
       if (file.ContentLength > 0)
       {
          file.SaveAs(/* path */);
       }
    
       // othyer tasks
    
       return RedirectToAction("Index");
    }
    

    The name attribute is what the browser will send on a post/get form when submit.

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

Sidebar

Related Questions

I'm really having a problem finding out how to fix this. I cannot seem
I'm having a problem that I can't seem to figure out, though I'm not
i having problem in converting this C# code into VB.net. The loadLecturer seem to
I'm having trouble finding an answer for this problem. Most similar posts lean seem
I seem to be having a problem withs tring encoding. I have the following
I seem to be having the same problem that everyone has with Struts2 and
I seem to be having a problem that jScrollPane doesn't seem to load on
I seem to be having a problem with JTextPane. I have extended JTextPane to
I seem to be having a problem with my SQL query that's driving me
I seem to be having a problem removing the image in UIScrollView. I was

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.