TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Marius Vasile
590
1.9k
145.7k
Asp.Net Core Razor display an error message from if...else
Dec 1 2020 11:46 PM
I have a button triggering OnPost action
<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
var checkIsoCert = await (from a
in
_context.IsoCerts.Where(s => s.PTWNo == idPTWNo)
join b
in
_context.IsoDetails on a.IdIC equals b.IdIC into TempData1
from c
in
TempData1
select
new
{ c.IsStatus }).ToListAsync();
string
myString =
"Awaiting"
;
var matchingvalues = checkIsoCert.Where(x => x.IsStatus.Equals(myString));
if
(matchingvalues ==
null
)
{
var ptwStatus = _context.PTWContents.First(s => s.PTWNo == idPTWNo);
ptwStatus.PTWStatus =
"Issued"
;
await _context.SaveChangesAsync();
return
RedirectToPage(
"PTWForm"
,
"PTWNoId"
,
new
{ ptwNoId = idPTWNo });
}
else
{
//show an error message such as -You have not complete IsoCert-
}
What I need is to display the message on error. How do I do that on Razor pages?
Reply
Answers (
18
)
Jquery to load page automatically
asp.net razor check if a list contain a string