My filter is not working as intended. I have a OnGet
- public async Task<IActionResult> OnGetAsync()
- {
- var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
- var orgid = await _context.UsersData.Where(s => s.Id == userId).Select(s => s.OrgID).FirstOrDefaultAsync();
- var todayYear = DateTime.Today.Year;
-
- PTWContentsL = await _context.PTWContents.Where(s => s.OrgID == orgid && s.StartDate.Year == todayYear).ToListAsync();
-
- return Page();
- }
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
- public async Task<IActionResult> OnPostFilteringIRAsync(string FilterIR)
- {
- Test = FilterIR;
- var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
- var orgid = await _context.UsersData.Where(s => s.Id == userId).Select(s => s.OrgID).FirstOrDefaultAsync();
- var todayYear = DateTime.Today.Year;
-
- PTWContentsL = await _context.PTWContents.Where(s => s.OrgID == orgid && s.StartDate.Year == todayYear && s.Issuer == FilterIR).ToListAsync();
-
- return Page();
- }
the View and form
- <form method="post">
- <div class="col-md-5 border border-primary pl-1">
- <div class="row no-gutters">
- <div class="col-md-12 text-center">
- <label class="form-control text-white" style="background-color:dodgerblue">Filter by Issuer/ Receiver</label>
- </div>
- </div>
- <div class="row no-gutters mb-1">
- <div class="col-md-10 mb-2">
- <select id="IRSelect" class="form-control ml-1">
- <option value="">--Select Filtering Condition--</option>
- <option value="1">Issuer</option>
- <option value="2">Receiver</option>
- </select>
- </div>
- <div class="col-md-10">
- <select id="IRDetail" class="form-control ml-1" asp-items="@(new SelectList(string.Empty, "Issuer", "Issuer"))" onchange="assignData()">
- <option value="">--Select Name--</option>
- </select>
- <input hidden id="IRName" asp-for="FilterIR" />
- </div>
- <div class="col-md-2 pl-1 text-center">
- <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" />
- </div>
- </div>
- </div>
- </form>