Reputation: 2767
In a ASP.NET Core 3.1 project using Razor Pages, I have the following page model:
[BindProperty]
public AddUserPageModel Input { get; set; }
public class AddUserPageModel
{
public string UserName { get; set; }
public string Password { get; set; }
public List<IFormFile> ImageUploads { get; set; }
}
From this Razor Page View, I insert a partial view and pass the model which is a single property:
<partial name="Partials/_AddPhotos" model="@Model.Input.ImageUploads" />
And in the Partial View:
@model List<Microsoft.AspNetCore.Http.IFormFile>
<input asp-for="@Model" type="file" multiple>
Which results in the following error:
System.ArgumentException: The name of an HTML field cannot be null or empty.
So it seems the issue is in the partial view, that asp-for="@Model"
needs a .PropertyName
but I'm not sure how to achieve this?
Upvotes: 1
Views: 347
Reputation: 8459
I think you can pass @Model.Input
to your partial view.
And use AddUserPageModel as the page model in your partial view.
@model Project.Models.AddUserPageModel
<input asp-for="@Model.ImageUploads" type="file" multiple>
Upvotes: 1