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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:53:50+00:00 2026-05-22T14:53:50+00:00

I am trying to make a file uploading page in my MVC project. First

  • 0

I am trying to make a file uploading page in my MVC project. First of all i want to manage this locally.
My Questions are:
1- Here is my controller and view. Is there any thing that I have to do to make this code work? I mean defining a model or using jquery, etc. What is the process when a file is being uploaded?

[HttpPost]
public ActionResult FileUpload(HttpPostedFileBase uploadFile)
{
if (uploadFile.ContentLength > 0)
            {
                string filePath = Path.Combine(HttpContext.Server.MapPath("C:/Users/marti/../PhotoGallery/myimages"),
                 Path.GetFileName(uploadFile.FileName));
                uploadFile.SaveAs(filePath);
            }
            return View();
}

Here is the View:

<input name="uploadFile" type="file" />
<input type="submit" value="Upload File" />

2- When i debug this, It never goes to controller.

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

    You may need the enctype='multipart/form-data' on your view form:

        @model ImageModel
        @{
            ViewBag.Title = "New Image";
        }
        <div class="content-form-container width-half">
            <form id='PropertiesForm' action='@Url.Action(ImageController.Actions.Add, ImageController.Name)' method='post' enctype='multipart/form-data' class='content-form'>
            @Html.Partial("ImageName")
            <fieldset class='content-form-1field'>
                <div class='legend'>
                    file to upload
                </div>
                @Html.LabelledFileInput(ImageView.FileName, string.Empty)
            </fieldset>
            <div class='buttons'>
                @Html.Button("button-submit", "submit")
            </div>
            </form>
        </div>
        @section script{
            @Html.JavascriptInclude("~/js/image/new.min.js")
        }
    

    And here is my controller code:

        [HttpPost]
        [MemberAccess]
        public ActionResult Add()
        {
            var name = ImageView.ImageName.MapFrom(Request.Form);
    
            if (Request.Files.Count == 0)
            {
                RegisterFailureMessage("No file has been selected for upload.");
    
                return ValidationFailureAdd(name);
            }
    
            var file = Request.Files[0];
    
            if (file == null || file.ContentLength == 0)
            {
                RegisterFailureMessage("No file has been selected for upload or the file is empty.");
    
                return ValidationFailureAdd(name);
            }
    
            var format = ImageService.ImageFormat(file.InputStream);
    
            if (format != ImageFormat.Gif && format != ImageFormat.Jpeg && format != ImageFormat.Png)
            {
                RegisterFailureMessage("Only gif, jpg and png files are supported.");
    
                return ValidationFailureAdd(name);
            }
    
            if (query.HasName(name))
            {
                RegisterFailureMessage(string.Format("Image with name '{0}' already exists.", name));
    
                return ValidationFailureAdd(name);
            }
    
            using (var scope = new TransactionScope())
            {
                var id = Guid.NewGuid();
    
                var fileExtension = ImageService.FileExtension(format);
    
                Bus.Send(new AddWikiImageCommand
                         {
                             Id = id,
                             Name = name,
                             FileExtension = fileExtension
                         });
    
                var path = Path.Combine(ApplicationConfiguration.MediaFolder,
                                        string.Format("{0}.{1}", id.ToString("n"), fileExtension));
    
                if (System.IO.File.Exists(path))
                {
                    System.IO.File.Delete(path);
                }
    
                file.SaveAs(path);
    
                scope.Complete();
            }
    
            return RedirectToAction(Actions.Manage);
        }
    

    There are some custom bits in there so you can ignore those. The gyst of what you need should be there.

    HTH

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

Sidebar

Related Questions

Hey I am trying to make a notification for my file uploading notification. This
i'm trying to make my site with a few languages. Every page includes config-file,
I'm trying to create a make file which will compile all the .cpp files
im' trying to make a file based article system and i want the folders
I was trying to make a file upload form and checked the PHP documentation
I am trying to make an xml file to export my data from my
I'm trying to make a HTML file with command line, but there is one
I'm trying to make a appcache file but got some problems... I've added the
I'm trying to make a spec file (rpm) for a insanely big software. The
Hi guys i am trying to create one simple make file and execute in

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.