1
I have the ActionResult Login that validates my user and saves the data in a Session, if everything goes ok, redirects to the 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");
}
}
To ActionResult BPAC needs a string calling for ibge to work, and I have to get the same Session established previously, but the system does not recognise 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 the Session here in my Controller?
I’ll need the data from
Sessionin otherViews, how to get through theSession?– Italo Rodrigo
use Viewbag. Ex. Viewbag.User and Viewbag.Password
– Marco Antonio Quintal