Parse-Vader
Parse-Vader

Reputation: 21

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>

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

Upvotes: 0

Views: 256

Answers (1)

Kiran Joshi
Kiran Joshi

Reputation: 1876

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();
    }
}
} 

Upvotes: 0

Related Questions