<pre lang="C#">public async Task<actionresult> PopulateFileCache(string folderPath) { if (!string.IsNullOrEmpty(folderPath)) { using var client = _httpClient.CreateClient("MesserAPI"); try { using var response = await client.GetAsync($"/api/File/GetFolderFiles?folderPath={folderPath}"); if (response.IsSuccessStatusCode) { var lstFiles = await response.Content.ReadAsStringAsync(); ViewData["lstParts"] = lstFiles; TempData["SlideTotal"] = 0; if (_contextAccessor.HttpContext.Session.IsAvailable) { SaveToSession(lstFiles); } TempData["guid"] = _contextAccessor.HttpContext.Session.GetString("sGUID") ?? string.Empty; } } catch (Exception ex) { _logger.LogError(ex.Message); } } return RedirectToAction("FileViewer"); } public IActionResult ReturnData(string sessionID) { //if (objFiles != null) //{ if (TempData != null) { TempData.Keep(); } List<lnpartvm> lNParts = null; try { //var jsonResponse = objFiles; //var jsonResponse = GetFromSession(); var jsonResponse = GetFromSession(sessionID); if (!string.IsNullOrWhiteSpace(jsonResponse)) { lNParts = JsonSerializer.Deserialize<list<lnpartvm>>(jsonResponse); } if (lNParts?.Count > 0) { TempData["SlideTotal"] = lNParts.Count; _contextAccessor.HttpContext.Session.SetInt32("SlideTotal", lNParts.Count); int partIndex = 0; try { partIndex = (int)(_contextAccessor.HttpContext.Session.GetInt32("PartIndex") == null ? 0 : _contextAccessor.HttpContext.Session.GetInt32("PartIndex")); } catch (Exception ex) { _logger.LogError(ex.Message); } LNPartVM partVM = lNParts[partIndex]; } catch (Exception ex) { _logger.LogError(ex.Message); } //} return ViewComponent("DataPage"); } public string GetSessionID() { return _contextAccessor.HttpContext.Session.Id; } public string GetSessionGUID() { return Guid.NewGuid().ToString(); } //string sessionName, public IActionResult SaveToSession(string obj) { bool status = false; // Same Session across browsers //string sessionID = GetSessionID(); string sessionID = GetSessionGUID(); if (!string.IsNullOrWhiteSpace(sessionID)) { _contextAccessor.HttpContext.Session.SetString(sessionID, obj); _contextAccessor.HttpContext.Session.SetString("sGUID", sessionID); status = true; } else { _contextAccessor.HttpContext.Session.SetString("SessionPN", obj); status |= true; } if (status) { return Content("Session Saved"); } return Content("Session Error"); } public async Task<iactionresult> FileViewer() { return View(); } This is on the HTML page $('#btnNext').click(function (e) { e.preventDefault(); console.log(iSlideCount); if (iSlideCount > 0) { $.ajax({ type: 'GET', url: '@Url.Action("NextPart", "File")', contentType: 'Json' }) .done(function(e) { var sguid = $("#txthguid").val(); var route = '@Url.Action("ReturnData","File", new { sessionID="-1" })'; route = route.replace("-1", sguid); $('#contentData').load(route); //$('#contentData').load('@Url.Action("ReturnData","File")'); //$('#part').load('@Url.Action("ReturnData","File")');
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)