Marius Vasile

Marius Vasile

  • 594
  • 1.9k
  • 144.8k

How can I have a specific tab refreshed on post in Asp.Net Core Razor

Aug 7 2020 2:27 AM
I have a tabbed Razor page, on load there is no data to be retrieved from server, active tab set for first tab. However, when I update data on one tab and post it I want the page to get only data for that tab. What I have so far is:
 
html:
 
  1. <ul class="nav nav-tabs" id="PTWTab" role="tablist">  
  2.         <li class="nav-item">  
  3.             <a class="nav-link active" id="PTW-tab" data-toggle="tab" href="#PTW" aria-controls="ptw" aria-selected="true" style="width:200px">Permit To Work</a>  
  4.         </li>  
  5.         <li class="nav-item">  
  6.             <a class="nav-link" id="HazId-tab" data-toggle="tab" href="#HazId" aria-controls="hazid" aria-selected="false" style="width:200px">Hazard Identification</a>  
  7.         </li>  
  8.         <li class="nav-item">  
  9.             <a class="nav-link" id="GasTest-tab" data-toggle="tab" href="#GasTest" aria-controls="gt" aria-selected="false" style="width:200px">Gas Testing</a>  
  10.         </li>  
  11.         <li class="nav-item">  
  12.             <a class="nav-link" id="IsoCert-tab" data-toggle="tab" href="#IsoCert" aria-controls="isocert" aria-selected="false" style="width:200px">Isolation Certificate</a>  
  13.         </li>  
  14.     </ul>  
cshtml for post:
 
  1. public async Task<IActionResult> OnPostIsoCertAsync(int? PTWNo)  
  2.         {  
  3.   
  4.             if (!ModelState.IsValid)  
  5.             {  
  6.                 return Page();  
  7.             }  
  8.   
  9.             var newIsoCert = await _context.ICContents.FindAsync(PTWNo);  
  10.   
  11.             if (newIsoCert == null)  
  12.             {  
  13.                 return NotFound();  
  14.             }  
  15.   
  16.             if (await TryUpdateModelAsync<ICContent>(  
  17.                          newIsoCert,  
  18.                          "ICContent",   // Prefix for form value.  
  19.                            c => c.IdICD,  
  20.                            c => c.IsoStep,  
  21.                            c => c.EquipmentID,  
  22.                            c => c.EquipmentDescription,  
  23.                            c => c.EnSource,  
  24.                            c => c.IsType,  
  25.                            c => c.IsMethod,  
  26.                            c => c.LockNo,  
  27.                            c => c.PreparedBy,  
  28.                            c => c.ImplementedBy,  
  29.                            c => c.VerifiedBy,  
  30.                            c => c.IsStatus))  
  31.             {  
  32.                 await _context.SaveChangesAsync();  
  33.                   
  34.                 return Page(); 
  35.             }  
  36.   
  37.             return Page();  
  38.         }  
 and cshtml for Get is:
 
  1. public async Task<IActionResult> OnGetIsoCertAsync(int ptwNoId)  
  2.         {  
  3.   
  4.             PTWIsoCert = await (from a in _context.ICDatas.Where(a => a.PTWNo == ptwNoId)  
  5.                                 orderby a.IdICD  
  6.                                 join b in _context.ICContents on a.IdICD equals b.IdICD into TempData1  
  7.                                 from c in TempData1  
  8.   
  9.                                 select new PTWIsoCert  
  10.                                 {  
  11.                                     IdICD = a.IdICD,  
  12.                                     PTWNo = ptwNoId,  
  13.                                     IsoDate = a.IsoDate,  
  14.                                     IsoStep = c.IsoStep,  
  15.                                     EquipmentID = c.EquipmentID,  
  16.                                     EquipmentDescription = c.EquipmentDescription,  
  17.                                     EnSource = (int)c.EnSource,  
  18.                                     IsType = (int)c.IsType,  
  19.                                     IsMethod = (int)c.IsMethod,  
  20.                                     LockNo = c.LockNo,  
  21.                                     PreparedBy = c.PreparedBy,  
  22.                                     ImplementedBy = c.ImplementedBy,  
  23.                                     VerifiedBy = c.VerifiedBy,  
  24.                                     IsStatus = (int)c.IsStatus  
  25.                                 }).ToListAsync();  
  26.               
  27.             return Page();  
  28.         }  
What I want is after I post data in the selected tab, to get it from server and keep the tab active and display it. Html for display is already setup, I didn't post it to not load too much data 

Answers (4)