0
Hello, I have a method to login the system, soon after I need the user to select an option in a dropdown and save this value in a Session. Now I need to put the stored value in Session, inside a LINQ query. I’ll post the codes, which you’ll understand better.
Method to store the die in a Session:
 public ActionResult Contrato()
    {      
        var contrato = new Usuario() { SqContrato = 0 };
        return View(contrato);
    }
    [HttpPost]
    public ActionResult Contrato(Int16? Contrato)
    {
        System.Web.HttpContext.Current.Session["Contrato"] = Contrato;
        return View();
    }
Method where I need to place the value stored by Session:
    public ViewResult Ferias()
    {
        var usuarios =
            funcionarioFeriasRepository.Lista.Where(r => r.slogin == autenticacaoProvider.UsuarioAutenticado.Login && r.SqContrato == "SESSION AQUI"
                .ToList();
        return View(usuarios);
    }
						
When creating Helper, I get the following error: "Portalrh.WebUI.Models.SessionHelper.Contract: cannot declare instance Members in a Static class", you know what could be?
– Randrade
@Renilsonandrade My own mistake. I edited the answer.
– Leonel Sanches da Silva
In the Get{Return Httpcontext.Current.Session["Contract"];} part I get the following error: "cannot Convert Expression type 'Object' to Return type int"
– Randrade
@Renilsonandrade I edited again
– Leonel Sanches da Silva
Between "(int)" and "Return" I get "Expression Expected"( but does not say which). And the rest I continue with the same error. "cannot Convert Expression type 'Object' to Return type int"
– Randrade
I made a convertTo, and it worked. get ' Return Convert.Toint16(Httpcontext.Current.Session["Contract"]); }
– Randrade
Thanks Gypsy Morrison Mendez, helped me a lot.
– Randrade