Wenn die Schaltfläche gedrückt wird, wird das Modell als ungültig angezeigt, da die Felder leer sind. Beim Betrachten des Modells sind alle Felder leer oder null. Wer weiß, wie dieses Problem zu lösen, dankAttributinformationen nicht gefunden
Home Controller
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> createOrderLine(Product models)
{
if (ModelState.IsValid)
{
db.OrderLines.Add(new OrderLine
{
productId = models.productId,
productColour = models.productColour,
productDescription = models.productDescription,
productName = models.productName,
productPrice = models.productPrice,
productStock = models.productStock,
//QuantityOrdered = quantityOrdered
});
db.SaveChanges();
return RedirectToAction("Index", "OrderLines");
}
else return RedirectToAction("Index", "Home");
}
Home Index - Zeigt die Produktinformationen auf dem Bildschirm
@foreach (var product in Model)
{
using (Html.BeginForm("createOrderLine", "Home", FormMethod.Post, new {
@class = "form-horizontal", role = "form" }))
{
<div class="row">
<div class="blog col-md-6">
<div>
<h1>Product Name</h1>
<h2>@product.productName</h2>
<div>
<h3>Product Description</h3>
<h6><i>@product.productDescription</i></h6>
<br />
<h3>Product Price</h3>
<td>@product.productPrice </td>
<br />
<h1>Product colour</h1>
<td>@product.productColour</td>
<div></div>
<br />
<br />
@Html.AntiForgeryToken()
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" class="btn btn-buy" value="Add to cart" onclick="btnbuy_Click" />
</div>
</div>
</div>
</div>
<br />
</div>
</div>
}
}
Ein Formular übermittelt nur die Name/Wert-Paare seiner erfolgreichen Formularsteuerelemente, und Sie generieren keine Formularsteuerelemente. Aber Sie können nur ein Formular einreichen, warum generieren Sie mehrere '