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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:26:08+00:00 2026-06-11T09:26:08+00:00

I am working on a simple form where user will enter some data and

  • 0

I am working on a simple form where user will enter some data and select a file to upload.
But i can not get this working..
For some reason when I click save, the file does not go to the controller.

Here is some code.

@using (Ajax.BeginForm("Add", "Category", null, new AjaxOptions
{
UpdateTargetId = "upload-message",
InsertionMode = InsertionMode.Replace,
HttpMethod = "POST",
OnSuccess = "uploadSuccess"
}, new { id = "AddCategoryForm", enctype = "multipart/form-data" }))
{
<div class="editorLabel">
    @Html.LabelFor(m=>m.CategoryName)
</div>
<div class="editorText">
    @Html.TextBoxFor(m=>m.CategoryName)
</div>
<div class="editorLabel">
    @Html.LabelFor(m => m.Description)
</div>
<div class="editorText">
    @Html.TextAreaFor(m => m.Description)
</div>

<div class="editorLabel">
    @Html.LabelFor(m => m.IconPath)
</div>
<div class="editorText">
    <input type="file" id="file" name="file" />
</div>
<div class="editorLabel">
    @Html.LabelFor(m => m.IsActive)
</div>
<div class="editorText">
    @Html.CheckBoxFor(m=>m.IsActive)
</div>
<p>
    <input type="submit" id="submit" value="Save" />
</p>

}

Controller:

[HttpPost]
    public ActionResult Add(HttpPostedFileBase file,CategoryViewModel model)
    {
        if (ModelState.IsValid)
        {
            System.IO.FileInfo info = new FileInfo(file.FileName);
            string ext = info.Extension;
            //other code
         }
      }

Here in the controller, file is always null.
Where am I doing wrong??

  • 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-11T09:26:09+00:00Added an answer on June 11, 2026 at 9:26 am

    First swapping parameters of your controller to have it as follows:

    [HttpPost]
    public ActionResult Add(CategoryViewModel model, HttpPostedFileBase file)
    

    For example.

    If this won’t work for some reason, make the file you uploading part of your model (CategoryViewModel) and have controller signature as follows:

    [HttpPost]
    public ActionResult Add(CategoryViewModel model)
    

    For example. That way file will be returned as part of the model and you will extract it as one of model’s properties. This will work (it worked for me).

    Hope this helps.

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

Sidebar

Related Questions

I'm working on an intermediary form that will gather some data from the user
I'm trying to make a simple form, but it's working not so fine. This
My javascript is not working right. It is simple pre-vailidation form and I can
I am working on a simple news module. There is a form where user
I am working on some simple form validation and need some assistance. Basically, I
I search for a working solution for a rather simple problem, but could not
I am working on a simple contact form written in php and have almost
I have simple php validation form that is halfway working. If you leave the
I have a simple form to enter details of a new case (kase), it's
I'm currently working on a simple form that stores users inputted information to a

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.