Retrieve Session value from request object

Posted by Shasseb under ASP.NET on 12/30/2012 | Points: 10 | Views : 927 | Status : [Member] | Replies : 5
Hello!

I want to retrieve value passed from one page in the session into another from request object using razor syntax.. so what should i do for it?
please guide me with a syntax for it...

Here is my code:
product.cshtml:
if(IsPost)
{
Session["ProductId"]=products.Id;
Session["BookName"]=products.Name;
//PageData["name"]="abc";
Session["BookPic"]=products.Book_Pic;
Session["Price"]=products.Price;
Session["Quantity"]=Quantity;
}

cart.cshtml
  var productID =Request["ProductId"].ToString();
var image = Request["BookPic"].ToString();
var price = Request["Price"].ToString();
var name= Request["BookName"].ToString();
var quantity=Request["Quantity"].ToString();

by using the above code i get an error that object is not set..
please help me...




Responses

Posted by: Shubham on: 12/31/2012 [Member] Starter | Points: 25

Up
0
Down
above code is right!!!!

create session
Session["sometext"]=textbox.text;

and retrieve session

string text= session["sometext"].Tostring();
try to remove ispostback or use string in place of var

make a method for session create and call to any event...

Thanks&Regards:-
Shubham Choudhary
Software Engineer
www.facebook.com/shubham.kunar

Shasseb, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hariinakoti on: 12/31/2012 [Member] Starter | Points: 25

Up
0
Down
yes shubham is correct try like this Shasseb

Thanks & Regards
Hari

Shasseb, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Baimey on: 12/31/2012 [Member] Starter | Points: 25

Up
0
Down
Object reference not set error raises in which line??

Please mark if the query is resolved
Thanks
Baimey

Please Mark as Answer If this Helps

Shasseb, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Baimey on: 12/31/2012 [Member] Starter | Points: 25

Up
0
Down
Please avoid using

Request["ProductId"].ToString()
But use Session("ProductId").ToString()

Please Mark as Answer If this Helps

Shasseb, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Shasseb on: 1/1/2013 [Member] Starter | Points: 25

Up
0
Down
Yes problem is solved.. Thanks everyone :)

Shasseb, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response