Marius Vasile

Marius Vasile

  • 552
  • 1.9k
  • 145.8k

asp.net core on filter empty fields are displayed

Mar 15 2021 3:41 PM
I have filter implemented for WOStatus. When app run, it will display an emty field. Details below
 
  1. [BindProperty(SupportsGet = true)]  
  2.         public string SearchWOStatus { get; set; }  
  3.         public async Task<IActionResult> OnGetAsync()  
  4.         {  
  5.             var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);  
  6.             var orgid = await _context.UsersData.Where(s => s.Id == userId).Select(s => s.OrgID).FirstOrDefaultAsync();  
  7.               
  8.             WOVL = await(from a in _context.WOMains.Where(s => s.OrgID == orgid)  
  9.                          join b in _context.WOInitiators on a.WOMainID equals b.WOMainID into Temp1  
  10.                          from c in Temp1.DefaultIfEmpty()  
  11.                          join d in _context.WOPlanners on a.WOMainID equals d.WOMainID into Temp2  
  12.                          from e in Temp2.DefaultIfEmpty()  
  13.                          select new WOViewIndex  
  14.                          {  
  15.                              WOMainID = a.WOMainID,  
  16.                              WONumber = a.WONumber,  
  17.                              WONumberS = e == null ? 0 : e.WONumberS,  
  18.                              CreateDate = a.CreateDate,  
  19.                              Deficiency = c.Deficiency,  
  20.                              Activity = e == null ? "--NONE--" : e.Activity,  
  21.                              WOStatus = e == null ? "--NONE--" : e.WOStatus  
  22.                          }).ToListAsync();  
  23.   
  24.             return Page();  
  25.         }  
  26.         public async Task<IActionResult> OnPost(string SearchWOStatus)  
  27.         {  
  28.             var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);  
  29.             var orgid = await _context.UsersData.Where(s => s.Id == userId).Select(s => s.OrgID).FirstOrDefaultAsync();  
  30.             if (SearchWOStatus != null)  
  31.             {  
  32.                 WOVL = await (from a in _context.WOMains.Where(s => s.OrgID == orgid)  
  33.                               join b in _context.WOInitiators on a.WOMainID equals b.WOMainID into Temp1  
  34.                               from c in Temp1.DefaultIfEmpty()  
  35.                               join d in _context.WOPlanners.Where(s => s.WOStatus.Equals(SearchWOStatus)) on a.WOMainID equals d.WOMainID into Temp2  
  36.                               from e in Temp2.DefaultIfEmpty()  
  37.                               select new WOViewIndex  
  38.                               {  
  39.                                   WOMainID = a.WOMainID,  
  40.                                   WONumber = a.WONumber,  
  41.                                   WONumberS = e == null ? 0 : e.WONumberS,  
  42.                                   CreateDate = a.CreateDate,  
  43.                                   Deficiency = c.Deficiency,  
  44.                                   Activity = e == null ? "--NONE--" : e.Activity,  
  45.                                   WOStatus = e.WOStatus  
  46.                               }).ToListAsync();  
  47.             }  
  48.   
  49.             return Page();  
  50.         }  
  1. <form method="post">  
  2.     <div class="row no-gutters">  
  3.         <div class="col-md-2 ml-2">  
  4.             <label class="form-control text-white" style="background-color:firebrick">Sort by WO Status</label>  
  5.         </div>  
  6.         <div class="col-md-2">  
  7.             <select id="woStatus" class="form-control" style="border-color:firebrick; color:firebrick" OnChange="assignData()">  
  8.                 <option value="">--Select WO Status--</option>  
  9.                 <option value="1">Initiated</option>  
  10.                 <option value="2">Reviewed</option>  
  11.                 <option value="3">Planned</option>  
  12.                 <option value="4">Approved</option>  
  13.                 <option value="5">Rejected</option>  
  14.                 <option value="6">Scheduled</option>  
  15.                 <option value="7">InProgress</option>  
  16.                 <option value="8">Completed</option>  
  17.                 <option value="9">Closed</option>  
  18.             </select>  
  19.             <input hidden asp-for="SearchWOStatus" id="WOStatusName" />  
  20.         </div>  
  21.         <div class="col-md-1 ml-1">  
  22.             <input class="btn btn-link" style="border-color:firebrick; color:firebrick; width:150px" type="submit" value="Filter by Status" />  
  23.         </div>  
  24.         <div class="col-md-1 ml-1">  
  25.             <a asp-route-page="/WO/Index" class="btn btn-link" style="border-color:firebrick; color:firebrick; width:150px">Show All</a>  
  26.         </div>  
  27.     </div>  
  28. </form>  
snap picture with view
 
 
 

Answers (6)