Marius Vasile

Marius Vasile

  • 594
  • 1.7k
  • 125.6k

Asp.Net Core Razor display an error message from if...else

Dec 1 2020 11:46 PM
I have a button triggering OnPost action
 
  1. <button asp-page-handler="PTWIssue" asp-route-idPTWNo="@Model.PTWNo" type="submit" class="btn btn-link text-info font-weight-bolder mt-2 mb-2" style="font-size:20px;" data-toggle="tooltip" data-placement="top" title="Issue the Permit to Work and send to Receiver">Issue Permit To Work</button>  
On OnPost I have a check for string. I want to verify that there is no status "Awaiting" and then continue with OnPost. If the check fail, I want a simple message "Error on check" and the process to not continue. I have the following
 
  1. var checkIsoCert = await (from a in _context.IsoCerts.Where(s => s.PTWNo == idPTWNo)  
  2.                                       join b in _context.IsoDetails on a.IdIC equals b.IdIC into TempData1  
  3.                                       from c in TempData1  
  4.                                       select new { c.IsStatus }).ToListAsync();  
  5.   
  6.             string myString = "Awaiting";  
  7.             var matchingvalues = checkIsoCert.Where(x => x.IsStatus.Equals(myString));  
  8.             if(matchingvalues == null)  
  9.             {  
  10.                 var ptwStatus = _context.PTWContents.First(s => s.PTWNo == idPTWNo);  
  11.                 ptwStatus.PTWStatus = "Issued";  
  12.                 await _context.SaveChangesAsync();  
  13.                 return RedirectToPage("PTWForm""PTWNoId"new { ptwNoId = idPTWNo });  
  14.             }  
  15.             else  
  16.             {  
  17.                 //show an error message such as -You have not complete IsoCert-  
  18.             }  
What I need is to display the message on error. How do I do that on Razor pages? 

Answers (18)