How to call another action and return the value?

2

Follow the code below:

public ActionResult Teste1(int num1, int num2)
{
   var valor = Teste2(1, 2); //Aqui recebe valor nulo
}

public ActionResult Teste2(int num11, int num22)
{
   //Alguns valores aqui...
   var valor = 123;
   return null;
}

The values that are in the action Teste2 , move to action Teste1 with variable valor , is this possible?

    
asked by anonymous 03.05.2017 / 00:21

1 answer

2
  

The values that are in the Test2 action, move to Test1 action with variable value, is this possible?

Possible, yeah, but that's a bad practice.

Notice that the return of Teste1 and Teste2 is ActionResult , that is, a complete result of an action executed on Controller . Therefore, it would not be bad practice if the idea were something like:

public ActionResult Teste1(int num1, int num2)
{
   return Teste2(1, 2); // veja este retorno.
}

public ActionResult Teste2(int num11, int num22)
{
   //Alguns valores aqui...
   var valor = 123;
   return Content(valor); // veja aqui também.
}
If the idea is reuse logic, declare Helpers (static classes with static methods inside), which are more efficient and the return is on variables that you define.

    
03.05.2017 / 00:25