I would like to move a data from an IActionResult to another IActionResult. I have stored the data of the product details in return View (cdd). How do I stored it into Tempdata in order for it to pass it to another view?
Here are my codes:
[HttpGet]
public IActionResult Details(int id)
{
string sql = String.Format(@"SELECT * FROM WBProduct
WHERE Id = {0}", id);
List<Product> lstProduct = DBUtl.GetList<Product>(sql);
if (lstProduct.Count == 0)
{
TempData["Message"] = $"Product #{id} not found";
TempData["MsgType"] = "warning";
return Index();
}
else
{
Product cdd = lstProduct[0];
return View(cdd);
}
}
I would like to call the data 'cdd' in this action method.
public IActionResult Create(Product product)
{
return View("Create", product);
}
Here is my view for Details Action Method:
@model List<Product>
@if (TempData["Message"] != null)
{
<div class="alert alert-@TempData["MsgType"]">
@TempData["Message"]
</div>
}
<table class="table table-condensed table-hover">
<tr>
<th scope="col">ID</th>
<th scope="col">Product</th>
<th scope="col">Price</th>
<th scope="col">Quantity</th>
</tr>
<tr>
<td>@ViewData["ID"]</td>
<td>@ViewData["Product"]</td>
<td>@ViewData["Price"]</td>
<td>@ViewData["Quantity"]</td>
<td>
<a asp-controller="Product"
asp-action="Delete">
Delete
</a>
</td>
<td>
<a asp-controller="Product"
asp-action="Checkout">
Checkout
</a>
</td>
</tr>
question from:
https://stackoverflow.com/questions/65649522/move-data-from-a-view-to-another-view 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…