ASP.NET Core 1.0 POST IEnumerable <T> to controller
Ich habe eine Aktion, die ein Modell an die Ansicht zurückgibt, bei der es sich um @ handelIEnumerable<T>
. In der Ansicht durchlaufe ich die Liste mit foreach. T-Typ hat eine Eigenschaft namens Amount.
Nun wenn ich auf @ klicSAVE
button, ich möchte das Modell (IEnumerable) zu einer Aktion POSTEN. Die IEnumerbale-Elemente, ihre EigenschaftenAmount
sollte die richtigen Werte enthalten.
Wenn ich es abschicke, ist das Modell in der Aktion null.
Zum Testen desIEnumerable<T>
istIEnumerable<Produt>
public class Product
{
public string Title { get; set; }
public int Amount { get; set; }
}
view Produkte anzeigen:
@model IEnumerable<Product>
<form asp-controller="Home" asp-action="Order" method="post" role="form">
@foreach (var product in Model)
{
<div>
<span>@product.Title</span>
<input asp-for="@product.Amount" type="text">
</div>
}
<button type="submit">SAVE</button>
</form>
controller post action:
[HttpPost]
public async Task<IActionResult> Order(IEnumerable<Product> model)
{
}