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.