❔ Session Variables

Storing what a user selects from a dropdown to a session variable but it gives a null error which should not be. looked for the error i know it lies here. tried for 2 days but no success. Just wondering is there another way to achieve my goal?
 cs  [HttpPost]
       public IActionResult Index(Student_List studentss)
        {
            int Studnentid = studentss.Stid;//problem is it is not showing the id or storing the id
            HttpContext.Session.SetInt32("Stid", Studnentid);//if i change studentid to 1 it works
            string studentname = studentss.StName;
            HttpContext.Session.SetString("StName", studentname);
            return RedirectToAction("Index", "Dashboard");
        }
    }
}

 cs
      @using (Html.BeginForm("Index", "Profile", FormMethod.Post))//new
    {
    <div class="form-control">
            <div class="col-md-3">
                @using (Html.BeginForm("",  "", FormMethod.Post))
                {
                    @Html.DropDownListFor(model => model.studlist, new SelectList(Model.studlist, "Stid", "StName")

                , new { @class = "form-control" })
                }
            </div>
            <button type="submit" class="btn btn-primary">Choose</button>
            </div>}
Was this page helpful?