0
    @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>

Is there a way to route the data in the IEnumerable Order to another Controller, using the send all button? or any other way?

Xinran Shen
  • 8,416
  • 2
  • 3
  • 12
  • what does `a way to route the data in the IEnumerable Order to another Controller` mean? `>` can only send get request, You need to make sure `SendToRabbit` is a HttpGet Method, And you can use `asp-route-xx` to pass data as query string. Or you can write a form to submit data with post request. – Xinran Shen Oct 11 '22 at 07:37

1 Answers1

0

You can use TempData to share the data from Action to Action and Controller to Controller. Just stored yout data in TempData and retrieved it in another controller method.

eg.

Method1Contoller

Public class Method1Contoller : Controller
{
public ActionResult Method1()
{
    TempData["Method1Data"] = "Your data";// you can store anything in this
    return RedirectToAction("Method2");
}
}

Method2Contoller

Public class Method2Contoller : Controller
{
public ActionResult Method2()
{
    if (TempData["Method1Data"] != null)
    {
        string data= (string) TempData["Method1Data"];
            ...
        return View();
    }
}
} 
Kiran Joshi
  • 1,758
  • 2
  • 11
  • 34
  • Thanks for your response, however i think you get me wrong.. While im on that View, i need to pass a List to another Controller from the View, i might be wrong but it looks like your doing the other way around, from controller to View.. – Parse-Vader Oct 11 '22 at 07:37
  • You can do same thing in View as well. Just set the data in TempData in view and fetch the same thing in other view with same approach. Is there any specific data you want to share of need to share whole the data of that view? – Kiran Joshi Oct 11 '22 at 07:41