Marius Vasile

Marius Vasile

  • 604
  • 1.7k
  • 124.4k

asp.net core filtering not working properly

Apr 15 2021 5:05 PM
My filter is not working as intended. I have a OnGet
 
  1. public async Task<IActionResult> OnGetAsync()  
  2. {  
  3.    var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);  
  4.    var orgid = await _context.UsersData.Where(s => s.Id == userId).Select(s => s.OrgID).FirstOrDefaultAsync();  
  5.    var todayYear = DateTime.Today.Year;  
  6.   
  7.  PTWContentsL = await _context.PTWContents.Where(s => s.OrgID == orgid && s.StartDate.Year == todayYear).ToListAsync();  
  8.   
  9. return Page();  
  10. }  
 which is listing all data but when I use a filter parameter is not working, I have empty results even if it should have at least all of the above. The parameter is sent because I checked on View
 
  1. public async Task<IActionResult> OnPostFilteringIRAsync(string FilterIR)  
  2.         {  
  3.             Test = FilterIR;  
  4.             var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);  
  5.             var orgid = await _context.UsersData.Where(s => s.Id == userId).Select(s => s.OrgID).FirstOrDefaultAsync();  
  6.             var todayYear = DateTime.Today.Year;  
  7.               
  8.             PTWContentsL = await _context.PTWContents.Where(s => s.OrgID == orgid && s.StartDate.Year == todayYear && s.Issuer == FilterIR).ToListAsync();  
  9.   
  10.             return Page();  
  11.         }  
 the View and form
 
  1. <form method="post">  
  2.     <div class="col-md-5 border border-primary pl-1">  
  3.         <div class="row no-gutters">  
  4.             <div class="col-md-12 text-center">  
  5.                 <label class="form-control text-white" style="background-color:dodgerblue">Filter by Issuer/ Receiver</label>  
  6.             </div>  
  7.         </div>  
  8.         <div class="row no-gutters mb-1">  
  9.             <div class="col-md-10 mb-2">  
  10.                 <select id="IRSelect" class="form-control ml-1">  
  11.                     <option value="">--Select Filtering Condition--</option>  
  12.                     <option value="1">Issuer</option>  
  13.                     <option value="2">Receiver</option>  
  14.                 </select>  
  15.             </div>  
  16.             <div class="col-md-10">  
  17.                 <select id="IRDetail" class="form-control ml-1" asp-items="@(new SelectList(string.Empty, "Issuer", "Issuer"))" onchange="assignData()">  
  18.                     <option value="">--Select Name--</option>  
  19.                 </select>  
  20.                 <input hidden id="IRName" asp-for="FilterIR" />  
  21.             </div>  
  22.             <div class="col-md-2 pl-1 text-center">  
  23.                 <input class="btn btn-link ml-2" asp-page-handler="FilteringIR" style="border-color:dodgerblue; color:dodgerblue; width:100px; font-size:14px" type="submit" value="Apply Filter" />  
  24.             </div>  
  25.         </div>  
  26.     </div>  
  27. </form>  
 

Answers (6)