How to send parameter to ActionResult?

1

I have ActionResult Login that validates my user and saves the data in a Session, if everything is ok, redirect to ActionResult BPAC :

[HttpPost]
public ActionResult Login(string pUsuario, string pSenha)
{
    oUsuario = modelOff.usuarios.SingleOrDefault(p => p.usuario1 == pUsuario && p.senha == pSenha);

    if (oUsuario == null)
    {
        return RedirectToAction("ErroLogin");
    }
    else
    {
        Session["usuario"] = oUsuario;
        return RedirectToAction("BPAC");
    }
}

The ActionResult BPAC needs a string called ibge to work, and I have to get it in the Session created previously, but the system does not recognize it.

public ActionResult BPAC()
{
    if (Session["usuario"] == null)
    {
        return RedirectToAction("ErroLogin");
    }
    string ibge = Session["usuario"].ibge; //<<<<< ERRO AQUI
    List<Estabelecimento> listaEstabelecimento = new Estabelecimento().listaEstabelecimento(ibge);
    return View(listaEstabelecimento);
}

This line I marked is not recognized by the system. How do I use Session here in my Controller ?

    
asked by anonymous 05.09.2017 / 20:06

1 answer

1

use RedirectToAction by passing the parameters.

return RedirectToAction("BPAC", new { pUsuario = "admin", pSenha = "xpto" });

and put the parameters in the action

public ActionResult BPAC(string pUsuario, string pSenha)
    
05.09.2017 / 20:11