Craig100
08/12/2023, 1:12 PMAnders Bjerner
08/12/2023, 1:55 PMAnders Bjerner
08/12/2023, 1:55 PMCraig100
08/12/2023, 2:33 PMvar test = HttpContext.Request.Form.Files;
gives count 0
Now I've changed the model from "string" to "object" I get:-
var test = model.SinglePhoto;
which is also empty, whereas it gave the file name when it was a string.Craig100
08/12/2023, 2:34 PMAnders Bjerner
08/12/2023, 2:35 PMCraig100
08/12/2023, 2:41 PM@using (Html.BeginForm("Submit", "MemorialFormSurface", FormMethod.Post, new { @id=formId, enqType="multipart/form-data" })) {
@Html.AntiForgeryToken()
<div>
<label asp-for="@Model.SinglePhoto">Please attach a photo of the person on their own.</label>
<div>
<input type="file" asp-for="@Model.SinglePhoto" data-val="false" data-val-required="Please select a single file in png, jpg, gif or webp format" accept=".jpg, .png, .gif, .webp">
<span asp-validation-for="@Model.SinglePhoto" data-valmsg-replace="true"></span>
</div>
</div>
<div>
<label asp-for="@Model.OtherPhotos">Please attach up to 5 other photos of the person.</label>
<div>
<input type="file" asp-for="@Model.OtherPhotos" multiple data-val="false" data-val-required="Please select a single file in png, jpg, gif or webp format" accept=".jpg, .png, .gif, .webp">
<span asp-validation-for="@Model.OtherPhotos" data-valmsg-replace="true"></span>
</div>
</div>
}
Anders Bjerner
08/12/2023, 2:47 PMasp-for="@Model.SinglePhoto"
Craig100
08/12/2023, 2:52 PM<form action="/umbraco/surface/memorialformsurface/Submit" enqType="multipart/form-data" id="a133e50a-432f-43f5-8fff-393a6985945a" method="post">
and the two file inputs look like this:-
<input type="file" data-val="false" data-val-required="Please select a single file in png, jpg, gif or webp format" accept=".jpg, .png, .gif, .webp" id="SinglePhoto" name="SinglePhoto">
<input type="file" multiple data-val="false" data-val-required="Please select a single file in png, jpg, gif or webp format" accept=".jpg, .png, .gif, .webp" id="OtherPhotos" name="OtherPhotos">
Craig100
08/12/2023, 2:54 PMAnders Bjerner
08/12/2023, 2:55 PMCraig100
08/12/2023, 2:59 PMCraig100
08/12/2023, 2:59 PMCraig100
08/12/2023, 3:17 PMvar test = model.SinglePhoto.SaveUploadedFileToTempFolder(IHostingEnvironment);
Anders Bjerner
08/12/2023, 3:21 PMIFormFile
sounds correct, but I can't get it to work with my test controllerCraig100
08/12/2023, 3:24 PMusing Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Core.Cache;
using Umbraco.Cms.Core.Logging;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Routing;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Web;
using Umbraco.Cms.Infrastructure.Persistence;
using Umbraco.Cms.Web.Website.Controllers;
using Web.Core.Models;
using Web.Core.Services;
namespace Web.Core.Controllers;
public class MemorialFormSurfaceController : SurfaceController {
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
private readonly IContentService _contentService;
private readonly IMediaService _mediaService;
private readonly Helpers _helpers;
private readonly IWebHostEnvironment _environment;
public MemorialFormSurfaceController(IUmbracoContextAccessor umbracoContextAccessor,
IUmbracoDatabaseFactory databaseFactory,
ServiceContext services,
IContentService contentService,
IMediaService mediaService,
AppCaches appCaches,
IProfilingLogger profilingLogger,
IPublishedUrlProvider publishedUrlProvider,
Helpers helpers,
IWebHostEnvironment environment) : base(umbracoContextAccessor, databaseFactory, services, appCaches, profilingLogger, publishedUrlProvider) {
_umbracoContextAccessor = umbracoContextAccessor;
_contentService = contentService;
_mediaService = mediaService;
_helpers = helpers;
_environment = environment;
}
[HttpPost]
public IActionResult Submit(MemorialFormModel model)
{
if (!ModelState.IsValid)
{
return CurrentUmbracoPage();
}
// All the other stuff......
}
Anders Bjerner
08/12/2023, 3:26 PMappplication/x-www-form-urlencoded
.Anders Bjerner
08/12/2023, 3:28 PMenqType
(with a q) opposed to encType
(with a c)Anders Bjerner
08/12/2023, 3:29 PMCraig100
08/12/2023, 3:30 PMCraig100
08/12/2023, 3:31 PMCraig100
08/12/2023, 3:32 PMAnders Bjerner
08/12/2023, 3:36 PMcsharp
public class CraigModel {
public IFormFile? SinglePhoto { get; set; }
public List<IFormFile>? OtherPhotos { get; set; }
}
Anders Bjerner
08/12/2023, 3:37 PMCraig100
08/12/2023, 3:42 PMCraig100
08/12/2023, 3:44 PMAnders Bjerner
08/12/2023, 3:50 PMA hub and casual space for you to interact with fellow community members and learn more about Umbraco!
Powered by