如何在类对象中获取Session的值?

Dhw*_*ani 5 c# asp.net-mvc-3

我为会话分配了一个自定义类的对象,如:

Services Obj = getServiceDetails(3); //getting all data of Service where Id = 3
Session["ServiceObj"] = Obj;
Run Code Online (Sandbox Code Playgroud)

现在我想将它的值赋给同一个类在模型类中的另一个对象.我不知道怎么做.

我尝试但是它无效的方式:

Services oldObj = <Services>Session["ServiceObj"];
Run Code Online (Sandbox Code Playgroud)

请帮助我.我不知道怎么做.

Igo*_*gor 10

正确的类型转换需要圆括号:

Services oldObj = (Services)Session["ServiceObj"];
Run Code Online (Sandbox Code Playgroud)