Im using a session variable to pass the user ID from the Index to the Create in the HomeController. ATM the user can use a drop down to select their name from the list of users and click View to list the holidays they have previously booked. From there the user can click create which will bring the user to a page which enables them to create a new holiday. From here they have to select their name again from the drop down list.
I want to store the users ID from the previous drop down so it will update automatically if they try to create another holiday (to replace the second drop down)
Im using a session variable to do this, iv put
Session["userameID"] = currentID;
in my view. Iv break pointed it just after and if I hold my mouse over currentID it displays the correct ID of the user.
So iv tried to pass this down to the create method using
string xx = (string)Session["usernameID"];
However, string ‘xx’ is returning NULL (tested with breakpoint)
I then placed the entire session in the view
Session["userameID"] = HolidayDate;
string xx = (string)Session["usernameID"];
and string xx is still returning null.
Is it not meant to return the userID???
Thanks for any replys
Two posible causes of your problem:
You are not using the same name for the session variable when you assign it and retrive it (userameID -> usernameID)
The type you assign is not a string, when you retrieve the value it can not be casted (assumed you solved issue 1)