Kapil Bhati

Kapil Bhati

  • NA
  • 256
  • 133k

Session values goes null in MVC controller

Nov 14 2017 7:08 AM
hi,
I am working with mvc. my code is working fine till last day.But now i am facing an strange problem. I have set a value in Session. Here is code

[code] 
public ActionResult RecordForEdit(string ID)
{
int Idd = Convert.ToInt32(ID);
Session["SubuserId"] = Idd;
var model = new SubUserModel();
model.UserName = obd_Sub.LoginId;
model.Pwd = obd_Sub.Password;
model.Status = obd_Sub.Status;
return View("SubUserIndex", model);
}[/code]
 
then in view a method is called by Jquery .
[code]
public JsonResult GetAssigned_Suburb()
{
string UId ="";
if (Session["SubuserId"] != null)
{
UId = Session["SubuserId"].ToString();
}
var Suburbs = odbe.ODB_GetSuburb_onload(UId);
var jsonResult = Json(Suburbs.ToList(), JsonRequestBehavior.AllowGet);
return jsonResult;
}
[/code]
in this method i get the value of Session["SubuserId"], then again on a button click a method is called. 
 
[code]
public JsonResult GetSuburb_ToAssign(string Pcode, string SubId)
{
string UId = Session["UserId"].ToString();
var UsrId = from s in odbe.ODB_UserMain where s.LoginId == UId select s;
string intId = UsrId.FirstOrDefault().Id.ToString();
string sub_Uid = "0";
if (Session["SubuserId"] != null)
{
sub_Uid = Session["SubuserId"].ToString();
}
var Suburb = odbe.ODB_GetSubuserSuburb_Count(Pcode, intId, sub_Uid);
var jsonResult = Json(Suburb.ToList(), JsonRequestBehavior.AllowGet);
return jsonResult;
}
[/code]
But in this method the method the value of Session["SubuserId"] is null. I not get how it is gone null. I have debug and googled alot but nothing found.

Answers (4)