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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:29:02+00:00 2026-05-18T01:29:02+00:00

Attempting to upload a file to a database and was wondering if someone could

  • 0

Attempting to upload a file to a database and was wondering if someone could help me a bit as I’ve gotten a bit stuck, and there are no errors. What happens is, my view displays where I go to upload my file. As soon as I hit the upload button it brings me back to the CreateCover upload page of the application, however it fails to upload anything to the database.

If anyone can offer any help I’d be delighted 🙂

PS: http://www.mikesdotnetting.com/Article/125/ASP.NET-MVC-Uploading-and-Downloading-Files –>This is the tutorial I was originally following. I was trying to use this as a base for what I wanted to do.

Here are the snippets of my code:

CoverController.cs

//
        //GET: /File/CreateCover
        public ActionResult CreateCover()
        {
            Cover cover = new Cover();

            return View(cover);
        }

        //
        //POST: /File/CreateCover
        [HttpPost]
        public ActionResult CreateCover(FormCollection formvalues)
        {
            Cover cover = new Cover();

            cover.CoverMimeType = Request.Files["CoverUpload"].ContentType;
            Stream fileStream = Request.Files["CoverUpload"].InputStream;
            cover.CoverFileName = Path.GetFileName(Request.Files["CoverUpload"].FileName);
            int fileLength = Request.Files["CoverUpload"].ContentLength;
            cover.CoverFileContent = new byte[fileLength];
            fileStream.Read(cover.CoverFileContent, 0, fileLength);

            filerepository.Save();

            return View(cover);
        }

Cover.cs

 [MetadataType(typeof(Cover_Validation))]
    public partial class Cover
    {
        //
    }

    public class Cover_Validation
    {
        [Required(ErrorMessage = "Please enter a file")]
        [StringLength(50, ErrorMessage = "You have not selected a cover image to upload")]
        public byte[] CoverFileContent;

        [Required(ErrorMessage = "A MimeType is required")]
        [StringLength(13, ErrorMessage = "Your file must contain a MimeType")]
        public string CoverMimeType { get; set; }

        [Required(ErrorMessage = "A Filename is required")]
        [StringLength(13, ErrorMessage = "Your file must have a filename")]
        public string CoverFileName { get; set; }
    }

Snippet from FileRepository relating to Adding Cover

//Insert Cover Data
public void AddCoverData(Cover cover)
{
    entities.Covers.AddObject(cover);
}

And finally here is the CreateCover view

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<SampleApp.Models.Cover>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    CreateCover
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <h2>CreateCover</h2>

    <% using (Html.BeginForm("CreateCover", "Cover", FormMethod.Post, new { enctype = "multipart/form-data" }))
       { %>
    <asp:Label ID="Label2" runat="server" Text="Please Select your eBook Cover" /><br />
    <input type="file" name="CoverUpload" /><br />
    <input type="submit" name="submit" id="Submit" value="Upload" />

    <% } %>

    <div>
        <%: Html.ActionLink("Back to List", "Index") %>
    </div>

</asp:Content>
  • 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-18T01:29:03+00:00Added an answer on May 18, 2026 at 1:29 am

    You’re being redirected to the home page because that’s where you are posting the form to.

    You need to post to the CreateCover action on your CoverController.

    E.g.

    <% using (Html.BeginForm("CreateCover",
                             "Cover",
                             FormMethod.Post,
                             new { enctype = "multipart/form-data" })) { %>
    

    HTHs,
    Charles

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

Sidebar

Related Questions

I am attempting to use FTP in Powershell to upload a file. I am
I'm attempting to upload a file into a jsp and then use the file
I have been unsuccesfully attempting to upload an encrypted file to an FTP server,
I am attempting to upload a file from my html page to my servlet
When attempting a file upload to an Alfresco Server using ssl the server logs
I'm running IIS 6.1 and I am attempting to upload a file through the
I'm attempting to upload an xml file to my site. However, regardless of which
I am attempting to have a file upload page that allows for an arbitrary
I am attempting to let a client upload a file to my server in
I am attempting to use the Jquery file upload addon to asynchronously upload files

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.