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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:29:56+00:00 2026-06-07T10:29:56+00:00

I have the ability to upload a file and save it to a directory.

  • 0

I have the ability to upload a file and save it to a directory. That is all good. I need to make an entry to my database with information about that file. So far I am not sure how to pass a value from the view to the controller in this particular case. I have tried to pass it as a method parameter but the value is not getting posted.

Here is my Razor form:

@using (Html.BeginForm("AjaxUpload", "Cases", FormMethod.Post, new { enctype = "multipart/form-data", id = "ajaxUploadForm" }))
        {
        <fieldset>
        <legend>Upload a file</legend>
        <label>File to Upload: <input type="file" name="file" />(100MB max size)</label>

        <input id="ajaxUploadButton" type="submit" value="Submit" />

        </fieldset>
        }
    <div id="attachments">
        @Html.Partial("_AttachmentList", Model.Attachments)
    </div>

Here is my jQuery to ajaxify the form:

$(function () {
    $('#ajaxUploadForm').ajaxForm({
        iframe: true,
        dataType: "json",
        beforeSubmit: function () {
            $('#ajaxUploadForm').block({ message: '<h1><img src="/Content/images/busy.gif" /> Uploading file...</h1>' });
        },
        success: function (result) {
            $('#ajaxUploadForm').unblock();
            $('#ajaxUploadForm').resetForm();
            $.growlUI(null, result.message);
            //$('#attachments').html(result);
        },
        error: function (xhr, textStatus, errorThrown) {
            $('#ajaxUploadForm').unblock();
            $('#ajaxUploadForm').resetForm();
            $.growlUI(null, 'Error uploading file');
        }
    });

});

Here is the controller method:

public FileUpload AjaxUpload(HttpPostedFileBase file, int cid)
        {
        file.SaveAs(Server.MapPath("~/Uploads/" + file.FileName));

        var attach = new Attachment { CasesID = cid, FileName = file.FileName, FileType = file.ContentType, FilePath = "Demo", AttachmentDate = DateTime.Now, Description = "test" };
        db.Attachments.Add(attach);
        db.SaveChanges();

        //TODO change this to return a partial view
        return new FileUpload { Data = new { message = string.Format("{0} uploaded successfully.", System.IO.Path.GetFileName(file.FileName)) } };
        }

I would like cid to be passed to this method so that I can insert a record into the database.

  • 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-07T10:29:57+00:00Added an answer on June 7, 2026 at 10:29 am

    You could include it as a hidden field inside the form:

    @Html.Hidden("cid", "123")
    

    or as a route value:

    @using (Html.BeginForm(
        "AjaxUpload", 
        "Cases", 
        new { cid = 123 },
        FormMethod.Post, 
        new { enctype = "multipart/form-data", id = "ajaxUploadForm" }
    ))
    {
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my web application users have the ability to upload games which are then
I'd like to have ability to resize pictures on my site. Algorithm: You upload
I see that some C libraries have ability to specify custom memory allocators (
Does JQuery have the ability to create an area that scrolls? Like I have
I need to have the ability to use superscripts asnd subscripts in a QLineEdit
I have a webpage that I don't have the ability to change the underlying
I'm building a site in Zend that requires the ability to upload a list
A client has the admin ability to upload a PDF to their respective directory
I am currently using the Zend Framework and have an upload file form. An
I have a form where I'm dynamically adding the ability to upload files with

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.