|
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
|
|
|
|
|
I dont know whether this a typo in your question or is it bug in your code but
Session["userameID"] = currentID;
and this
string xx = (string)Session["usernameID"]; definitely dont match.
The spelling of the session key is different. one place it is userameID and another it is usernameID .
Twenty years from now you will be more disappointed by the things that you didn't do than by the ones you did do. So throw off the bowlines. Sail away from the safe harbor. Catch the trade winds in your sails. Explore, Dream. Discover.
|
|
|
|
|
opps, thanks for that feeling tired this morning and missed that.
Anyway i
|
|
|
|
|
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, My View:
//this coverts the user ID to a string and stores it in
session["usernameID"]
string userID = currentPersonID.ToString();
Session["usernameID"] = userID;
-------------------------------------------------
//My Create:
//catches the session["UsernameID"], stores it in string 'xx'
//converts it to an int and stores it in currentPersonID
//then store the value of currentpersonID in the model
public ActionResult Create()
{
string xx = (string)Session["usernameID"];
int? currentPersonID = Convert.ToInt32(xx);
HolidayList model = new HolidayList();
model.currentPersonID = currentPersonID.Value;
-------------------------------------------------
This all works fine, howeve how do I display the value properly in the view?
Where I was using :
@Html.DropDownListFor(model => model.PersonId, new SelectList(ViewBag.Id, "Value", "Text"),"---Select---")
i've tried:
@Html.TextBoxFor(model =>model.currentPersonID, "currentPersonID")
//and
@Html.LabelFor(model =>model.currentPersonID)
hoping the correct ID would display, but only the text 'currentPersonID is displayed
please advise, thanks again
|
|
|
|
|
You try to get sessiondata in data format which you have stored like
if userid is integer then try to get data in integer only use type casting
|
|
|
|