What I am trying to do is to save a List
into TempData, that I'm later casting back to its type and passing to a view but the TempData after returning from a controller loses its data.
Controller A:
public ActionResult Index(int? Page, int? id, int? attId, int? EnrollNumber, int? attend, DateTime? reqDate, DateTime? reqDT, DateTime? reqTime, DateTime? StartDate, string deets = " ", string preAppr = "", string type = "")
{
//some code
new UserInfoController().reLabelLogs(reqTime.Value.Date, reqTime.Value, id, 0, 0, null, attLogs);
var atLogs = new List<AttendanceLog>();
var temp = TempData["ppList"]; //its empty?
atLogs = (List<AttendanceLog>)TempData["ppList"];
return View(atLogs);
}
Controller UserInfo:
public void reLabelLogs(DateTime? startDate, DateTime? startDateTime, int? empId, int? isPending, int? isManual, DateTime? manualDate
, List<AttendanceLog> pList)
{
//some code
if (pList == null)
{
data = db.AttendanceLogs
.Where(z => z.EmpID == empId && z.Date >= startDate && z.Date <= today).ToList();
}
else
{
noSave = true;
data = pList.ToList();
}
foreach (var log in data)
{
// some code
}
TempData["ppList"] = data; //there is data but soon after the control goes back to Controller A it becomes null
}
What did I try?
I tried using:
Session (but it would give NullException at UserInfoController)
ViewBag.ppList (same result as TempData)
Tried TempData.Keep(); and TempData.Peek(); (no help)