[英]Is there a way to route all @model data to another controller from a View in MVC?
@model IEnumerable<Order>
@if (TempData["SuccesMessage"] != null)
{
<div class="alert alert-success">
<strong> Succes! </strong>@TempData["SuccesMessage"]
</div>
}
<div class="container p-4 border">
<div class="row pb-2">
<h1 class="text-primary">All Orders</h1>
</div>
<div class="col text-end pt-1">
<a asp-controller="RabbitMQ" asp-action="SendToRabbit" class="btn btn-primary"> Send all </a>
</div>
有沒有辦法使用發送所有按鈕將 IEnumerable Order 中的數據路由到另一個 Controller? 或任何其他方式?
您可以使用 TempData 共享從 Action 到 Action 和 Controller 到 Controller 的數據。只需將您的數據存儲在 TempData 中,然后在另一個 controller 方法中檢索它。
例如。
方法1控制器
Public class Method1Contoller : Controller
{
public ActionResult Method1()
{
TempData["Method1Data"] = "Your data";// you can store anything in this
return RedirectToAction("Method2");
}
}
方法2控制器
Public class Method2Contoller : Controller
{
public ActionResult Method2()
{
if (TempData["Method1Data"] != null)
{
string data= (string) TempData["Method1Data"];
...
return View();
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.