0

I have 1 form with a simple dropdownbox with values from a database on Post the value of that dropbox gets inserted in a session. I think use that session value on the create page to autofill some categories but somehow it seems like the session becomes NULL or Empty on the second page.

form 1 action

   [HttpPost]
      public ActionResult select(listings listing)
    {
        Session["address"] = ViewBag.CategoryID;

        return View();
    } 

form 1 view

<form method="post" action="create">  
@Html.DropDownList("CategoryID")
<input type="submit" value="step 2"/>            
  </form>

Form 2 action

public ActionResult Create()
    {
  // The "IF" works correctly but it seems like it is making the SESSION= NULL
         if (Session["address"] == null)
        {
           return RedirectToAction("sesserror");

        }
        string tt = (string)Session["address"];
        var getlisting = (from s in db.relistings where tt==s.address select s).FirstOrDefault();

        return View();
    } 

The issue looks like maybe its in the IF statement if I go to FORM 1 pick a value and go to FORM 2 it does not redirect me so either the SESSION has a value and it is losing it or something else.

Form 2 View /create page

 <b>Step: 2 out of 2</b>  
@Session["address"]

I have more on Form 2 but i'm focusing on that part. Is there a better way to carry a value from 1 form to the other? by the way the Session does work initially because if I go straight to Form 2 I get redirected to Sesserror.

user1591668
  • 2,591
  • 5
  • 41
  • 84
  • [Check this](http://stackoverflow.com/a/7993283/1551730) it may help you – Karthik Chintala Jan 03 '13 at 09:00
  • "so either the SESSION has a value and it is losing it or something else." = You really need to learn how to debug--set breakpoints, step through your code, check the value of `Session["address"]` and see what is actually happening instead of postulating. – Forty-Two Jan 03 '13 at 14:04

0 Answers0