Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. [session] returns null

[session] returns null

Scheduled Pinned Locked Moved ASP.NET
databasedebuggingquestionannouncement
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    xnaLearner
    wrote on last edited by
    #1

    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

    R C 2 Replies Last reply
    0
    • X xnaLearner

      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

      R Offline
      R Offline
      Rahul Rajat Singh
      wrote on last edited by
      #2

      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.

      X 2 Replies Last reply
      0
      • R Rahul Rajat Singh

        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.

        X Offline
        X Offline
        xnaLearner
        wrote on last edited by
        #3

        opps, thanks for that feeling tired this morning and missed that.

        Anyway i've made an edit to the Q if you can see my original post that would be great Thanks

        1 Reply Last reply
        0
        • R Rahul Rajat Singh

          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.

          X Offline
          X Offline
          xnaLearner
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • X xnaLearner

            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

            C Offline
            C Offline
            Chandrabhan Sangale
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups