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>
It seems that you are trying to upload files here. Checkout the following blog post. You will need to use a
multipart/form-dataenctype for your form in order to be able to upload files. So the first step is to fix your form definition:then update your view model so that it takes the uploaded file as property:
and and finally have your controller POST action take this view model as parameter: