A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://stackoverflow.com/questions/79702316/binding-list-of-objects-with-dynamic-form below:

asp.net core mvc - Binding list of objects with dynamic form

Here's my current structure. Using a Pet example cause it's easier than explaining my domain.

Working backwards, Create should receive a List<Pet> with the Name, FileUpload and Selected Breed.

GetForm generates the view for a single Pet.

Manage is expecting one or multiple Pets.

With a single form, I'd do

@model MyPet
<input asp-for="FileUpload" name="FileUpload" type="file" accept=".png" />

With a multiple pet static form, I'd do something like

@model MyListOfPets

@for (int i = 0; i < Model.Pets.Count; i++)
{
    <input asp-for="FileUpload[i]" name="FileUpload" type="file" accept=".png" />
}

But with a dynamic form, where the partial view should only have one Pet, and the view that does the POST several, I have no idea how to do the binding... The partial view will only accept a single Pet and not the [i]


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4