Jude
Jude

Reputation: 2433

Pass Data to MVC Action Method

I need to pass data to the action method below from another action method or another view. Then it will be used where the arrow points. But this action method already has a parameter and get value from its own view. And it mustn't have more than one parameter. I don't know how. enter image description here

Upvotes: 0

Views: 416

Answers (1)

Lin
Lin

Reputation: 15188

Try to use TempData like below examples:

pass data from action to another action

public ActionResult Action_A()
{
    TempData["Data"] = "ABC";

    return View();
}


public ActionResult Action_B()
{
    var data = TempData["Data"];

    return View();
}

pass data from action view to another action

Action View

 @{
    TempData["Data"] = "hello";
  }
  <p>This is a Demo</p>

Another Action

  public ActionResult Action_B()
    {
        var data = TempData["Data"];

        return View();
    }

Upvotes: 1

Related Questions