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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:37:14+00:00 2026-05-23T13:37:14+00:00

I have gotten this semi autogenerated code, but I am uncertain where the Post

  • 0

I have gotten this semi autogenerated code, but I am uncertain where the Post data is saved and how I access the variables in my controller so I can validate and upload it to my database.

    @model FirstWeb.Models.Picture

@{
    ViewBag.Title = "Upload et billede";

}

<h2>Upload et billede</h2>

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>



@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)
    <fieldset>

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

        <div class="editor-label">
            @Html.LabelFor(model => model.Title)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Title)
            @Html.ValidationMessageFor(model => model.Title)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.ConcertYear)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.ConcertYear)
            @Html.ValidationMessageFor(model => model.ConcertYear)
        </div>

        <p>
            <input type="submit" value="Upload" />
        </p>
    </fieldset>
}

<div>
    @Html.ActionLink("Tilbage til billeder", "Index")
</div>
  • 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-23T13:37:15+00:00Added an answer on May 23, 2026 at 1:37 pm

    It seems that you are trying to upload files here. Checkout the following blog post. You will need to use a multipart/form-data enctype for your form in order to be able to upload files. So the first step is to fix your form definition:

    @using (Html.BeginForm(null, null, FormMethod.Post, new { enctype = "multipart/form-data" })) 
    {
        ...
    }
    

    then update your view model so that it takes the uploaded file as property:

    public class Picture
    {
        public HttpPostedFileBase File { get; set; }
        public string Title { get; set; }
        public int ConcertYear { get; set; }
    
        ... some other properties used in the view
    }
    

    and and finally have your controller POST action take this view model as parameter:

    [HttpPost]
    public ActionResult Foo(Picture model)
    {
        if (!ModelState.IsValid)
        {
            // there were validation errors => re-display the view
            return View(model);
        }
    
        // the model is valid at this stage => check if the user uploaded a file
        if (model.File != null && model.File.ContentLength > 0)
        {
            // the user uploaded a file => process it ...
        }
        ...
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've searched for this a little but I have not gotten a particularly straight
I guess the topic says it. I have tried googling this, but havent gotten
I have never gotten this error before so I am not sure what to
I have never gotten this to work. What the heck am I doing wrong?
I have gotten everything working for my class in which I am using Tomcat
I have been searching everywhere for the following functionality in Lisp, and have gotten
I am working on Conway's Game of Life currently and have gotten stuck. My
Have you guys had any experiences (positive or negative) by placing your source code/solution
Have just started using Google Chrome , and noticed in parts of our site,
Have you ever seen any of there error messages? -- SQL Server 2000 Could

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.