How to recover parameter from a Controller

Asked

Viewed 80 times

0

After the user logs in, two parameters are passed to Controller Home:

case SignInStatus.Success:
{
   //recupera as informações do usuario que corresponda ao usuario e password
   var user = await UserManager.FindAsync(model.Usuário, model.Password);

   //redireciona o login para o index o controller home
   return RedirectToAction("Index", "Home", new { 
           cod_cli = user.cod_cli, 
           razao_social = user.razao_social 
   });
}   

However, on another page I have a button that also redirects to Action Index of Controller Home:

@Html.ActionLink("OneeWeb", "Index", "Home", new { 
      area = "", 
      cod_cli = "parametro1", 
      razao_social = "parametro2" 
}, new { @class = "navbar-brand" })

My question is, how do I recover these parameters? they do not change, are fixed for each user.

In this case, it would be good to keep these parameters in the Cookie?

1 answer

0

I managed to solve the problem by starting to work with Sessions.

For further information: What’s the difference between Sessions and Cookies

After user login, the object with the user data is obtained:

case SignInStatus.Success:
                {
                    //recupera as informações do usuario que corresponda ao usuario e password
                    var user = await UserManager.FindAsync(model.Usuário, model.Password);                       
                    Session["cod_cli"] = user.cod_cli;
                    Session["razao_social"] = user.razao_social;

                    //redireciona o login para a pagina que o usuario estava.
                    //return RedirectToLocal(returnUrl);
                    //redireciona o login para o index o controller home
                    return RedirectToAction("Index", "Home", new { cod_cli = Session["cod_cli"], razao_social = Session["razao_social"] });
                }  

And then I use two Session to "save" the data you need, and then use on other pages..

Browser other questions tagged

You are not signed in. Login or sign up in order to post.