How can I access a session from a model?
You can always do the following pornography:
HttpContext.Current.Session["Consul"]
But please, oh, my holy land, please promise me never to commit such a crime.
A model should never know what a session is. Session is a web term and the Model must be completely agnostic. You must pass the information required by the Model from the controller that has access to the session.
So check this out:
public IQueryable<EstudentsViewModel> GetEstudentsProjected(decimal? Code, decimal id) { ... }
And when you call this method from the controller, you simply pass the value from the session, because the controller has access to it.
source share