Click here to Skip to main content
14,828,866 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
C#
  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);
}

then in view a method is called by Jquery .
C#
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;
       }

in this method i get the value of
Session["SubuserId"]
, then again on a button click a method is called.
C#
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;
        }    

But in this method the method the value of
Session["SubuserId"]
is null. I not get how it is gone null.

Thanks

What I have tried:

I have debug and googled alot but nothing found
Posted
Updated 10-Nov-17 2:14am
Comments
F-ES Sitecore 10-Nov-17 4:47am
   
How are you calling the method where the session doesn't work?
ErBhati 10-Nov-17 6:44am
   
ErBhati 10-Nov-17 6:46am
   
     <td><a href='@Url.Action("RecordForEdit", "SubUser", new { ID = val.Id })'>
<img class="btnedit" src="/../Content/images/edit.png" /></a></td> 

1 solution

You should pass the value throuth tempdate object
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900