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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:44:11+00:00 2026-05-14T04:44:11+00:00

I am attempting to create a form where a user is able to enter

  • 0

I am attempting to create a form where a user is able to enter your typical form values textboxes etc, but also upload a file as part of the form submission. This is my View code it can be seen that the File upload is identified by the MCF id:

<% using (Html.BeginForm("Create", "Problem", FormMethod.Post, new { id = "ProblemForm", enctype = "multipart/form-data" }))
   {%>

        <p>
            <label for="StudentEmail">Student Email (*)</label>
            <br />
            <%= Html.TextBox("StudentEmail", Model.Problem.StudentEmail, new { size = "30", maxlength=26 })%>
            <%= Html.ValidationMessage("StudentEmail", "*") %>
        </p>
        <p>
            <label for="Type">Communication Type (*)</label>
            <br />
            <%= Html.DropDownList("Type") %>
            <%= Html.ValidationMessage("Type", "*") %>
        </p>
        <p>
            <label for="ProblemDateTime">Problem Date (*)</label>
            <br />
            <%= Html.TextBox("ProblemDateTime", String.Format("{0:d}", Model.Problem.ProblemDateTime), new { maxlength = 10 })%>
            <%= Html.ValidationMessage("ProblemDateTime", "*") %>
        </p>
        <p>
            <label for="ProblemCategory">Problem Category (* OR Problem Outline)</label>
            <br />
            <%= Html.DropDownList("ProblemCategory", null, "Please Select...")%>
            <%= Html.ValidationMessage("ProblemCategory", "*")%>
        </p>
        <p>
            <label for="ProblemOutline">Problem Outline (* OR Problem Category)</label>
            <br />
            <%= Html.TextArea("ProblemOutline", Model.Problem.ProblemOutline, 6, 75, new { maxlength = 255 })%>
            <%= Html.ValidationMessage("ProblemOutline", "*") %>
        </p>
        <p>
            <label for="MCF">Mitigating Circumstance Form</label>
            <br />
            <input id="MCF" type="file" />
            <%= Html.ValidationMessage("MCF", "*") %>
        </p>
        <p>
            <label for="MCL">Mitigating Circumstance Level</label>
            <br />
            <%= Html.DropDownList("MCL") %>
            <%= Html.ValidationMessage("MCL", "*") %>
        </p>
        <p>
            <label for="AbsentFrom">Date Absent From</label>
            <br />
            <%= Html.TextBox("AbsentFrom", String.Format("{0:d}", Model.Problem.AbsentFrom), new { maxlength = 10 })%>
            <%= Html.ValidationMessage("AbsentFrom", "*") %>
        </p>
        <p>
            <label for="AbsentUntil">Date Absent Until</label>
            <br />
            <%= Html.TextBox("AbsentUntil", String.Format("{0:d}", Model.Problem.AbsentUntil), new { maxlength = 10 })%>
            <%= Html.ValidationMessage("AbsentUntil", "*") %>
        </p>
        <p>
            <label for="AssessmentID">Assessment Extension</label>
            <br />
            <%= Html.DropDownList("AssessmentID") %>
            <%= Html.ValidationMessage("AssessmentID", "*") %>

            <%= Html.TextBox("DateUntil", String.Format("{0:d}", Model.AssessmentExtension.DateUntil), new { maxlength = 16 })%>
            <%= Html.ValidationMessage("DateUntil", "*") %>
        </p>
        <p>
            <label for="Details">Assessment Extension Details</label>
            <br />
            <%= Html.TextArea("Details", Model.AssessmentExtension.Details, 6, 75, new { maxlength = 255 })%>
            <%= Html.ValidationMessage("Details", "*") %>
        </p>
        <p>
            <label for="RequestedFollowUp">Requested Follow Up</label>
            <br />
            <%= Html.TextBox("RequestedFollowUp", String.Format("{0:d}", Model.Problem.RequestedFollowUp), new { maxlength = 16 })%>
            <%= Html.ValidationMessage("RequestedFollowUp", "*") %>
        </p>
        <p>
            <label for="StaffEmail">Staff</label>
            <br />
            <%= Html.ListBox("StaffEmail", Model.StaffEmail, new { @class = "multiselect" })%>
            <%= Html.ValidationMessage("StaffEmail", "*")%>
        </p>
        <p>
            <input class="button" type="submit" value="Create Problem" />
        </p>

This is my controller code:

        [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult Create(Problem problem, AssessmentExtension assessmentExtension, Staff staffMember, HttpPostedFileBase file, string[] StaffEmail)
    {
        if (ModelState.IsValid)
        {
            try
            {

                Student student = studentRepository.GetStudent(problem.StudentEmail);
                Staff currentUserStaffMember = staffRepository.GetStaffWindowsLogon(User.Identity.Name);

                var fileName = Path.Combine(Request.MapPath("~/App_Data"), Path.GetFileName(file.FileName));
                file.SaveAs(@"C:\Temp\" + fileName);

                if (problem.RequestedFollowUp.HasValue)
                {
                    String meetingName = student.FirstName + " " + student.LastName + " " + "Mitigating Circumstance Meeting";
                    OutlookAppointment outlookAppointment = new OutlookAppointment(currentUserStaffMember.Email, meetingName, (DateTime)problem.RequestedFollowUp, (DateTime)problem.RequestedFollowUp.Value.AddMinutes(30));
                }

                problemRepository.Add(problem);
                problemRepository.Save();

                if (assessmentExtension.DateUntil != null)
                {
                    assessmentExtension.ProblemID = problem.ProblemID;
                    assessmentExtensionRepository.Add(assessmentExtension);
                    assessmentExtensionRepository.Save();
                }

                ProblemPrivacy problemPrivacy = new ProblemPrivacy();
                problemPrivacy.ProblemID = problem.ProblemID;
                problemPrivacy.StaffEmail = currentUserStaffMember.Email;
                problemPrivacyRepository.Add(problemPrivacy);

                if (StaffEmail != null)
                {
                    for (int i = 0; i < StaffEmail.Length; i++)
                    {
                        ProblemPrivacy probPrivacy = new ProblemPrivacy();
                        probPrivacy.ProblemID = problem.ProblemID;
                        probPrivacy.StaffEmail = StaffEmail[i];
                        problemPrivacyRepository.Add(probPrivacy);
                    }
                }

                problemPrivacyRepository.Save();

                return RedirectToAction("Details", "Student", new { id = student.Email });

            }
            catch
            {
                ModelState.AddRuleViolations(problem.GetRuleViolations());
            }
        }

        return View(new ProblemFormViewModel(problem, assessmentExtension, staffMember));
    }

This form was working correctly before I had to switch to using a non-AJAX file upload, this was due to an issue with Flash when enabling Windows Authentication which I need to use.

It appears that when I submit the form the file is not sent and I am unsure as to why? I have also been unsuccessful in finding an example online where a file upload is used in conjunction with other input types.

Another query I have is that for Create, and Edit operations I have used a PartialView for my forms to make my application have higher code reuse. The form action is normally generated by just using:

Html.BeginForm()

And this populates the action depending on which Url is being used Edit or Create. However when populating HTML attributes you have to provide a action and controller value to pass HTML attributes.

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

Is it possible to somehow populate the action and controller value depending on the URL to maintain code reuse? Thinking about it whilst typing this I could set two values in the original controller action request view data and then just populate the value using the viewdata values?

Any help on these two issues would be appreciated, I’m new to asp.net mvc 🙂

Thanks,

Jon

ANSWER

Ok guys worked out the issue and its incredibly simple I didn’t have the HTML name attribute on the file component of my form:

<input id="MCF" name="MCF" type="file" />

Now this binds to my method signature!

  • 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-14T04:44:11+00:00Added an answer on May 14, 2026 at 4:44 am

    Ok guys worked out the issue and its incredibly simple I didn’t have the HTML name attribute on the file component of my form:

    <input id="MCFile" name="MCFile" type="file" />
    

    I have changed my method signature to match the name:

    public ActionResult Create(Problem problem, AssessmentExtension assessmentExtension, Staff staffMember, HttpPostedFileBase MCFFile, string[] StaffEmail)
    

    Now this binds to my method signature!

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

Sidebar

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.