當用戶打開表單時,我希望我添加到產品實體的資料在表單中可見,但我的產品實體沒有顯示在我的表單上。我錯過了什么?
我的代碼:
public IActionResult CreateProduct()
{
var product = new Products() {
ProductName = "name",
Quantity = 5
};
return View(product);
}
[HttpPost]
public IActionResult CreateProduct(Products product)
{
return View();
}
**VIEW**
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@model Products
<form asp-action="CreateProduct" asp-controller="ModelB" method="post">
@Html.TextBoxFor(a => a.ProductName, "", new { placeholder = "Product Name" })
<br />
@Html.TextBoxFor(a => a.Quantity, "", new { placeholder = "Quantity", type = "number" })
<br />
<button type="submit">add</button>
</form>
uj5u.com熱心網友回復:
嘗試將您的操作重命名為 Index
[Route("~/home/index")]
public IActionResult Index()
{
var product = new Products() {
ProductName = "name",
Quantity = 5
};
return View(product);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/408228.html
標籤:
上一篇:使用Aforge捕獲桌面
