无法在表格中显示数据
Can't show the data in form
当用户打开表单时,我希望我添加到产品实例的数据在表单中可见,但我的产品实例没有显示在我的表单上。我错过了什么?
我的代码:
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>
尝试将您的操作重命名为索引
[Route("~/home/index")]
public IActionResult Index()
{
var product = new Products() {
ProductName = "name",
Quantity = 5
};
return View(product);
}
当用户打开表单时,我希望我添加到产品实例的数据在表单中可见,但我的产品实例没有显示在我的表单上。我错过了什么?
我的代码:
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>
尝试将您的操作重命名为索引
[Route("~/home/index")]
public IActionResult Index()
{
var product = new Products() {
ProductName = "name",
Quantity = 5
};
return View(product);
}