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
594
1.9k
145.6k
ASP.NET Core Razor Page OnPost with parameter
Oct 26 2020 10:53 AM
I have a Razor page which OnGet receive a parameter from another page and load the data. The OnGet looks like below
public
async Task<IActionResult> OnGetPTWNoIdAsync(
int
ptwNoId)
{
some code here
}
OnPost looks like below
public
async Task<IActionResult> OnPostHazIdAsync()
{
if
(!ModelState.IsValid)
{
return
Page();
}
var newHazId =
new
HazId();
if
(await TryUpdateModelAsync(newHazId,
"HazId"
,
c => c.PTWNo,
c => c.HazClass,
c => c.HazDetails,
c => c.HazPMClass,
c => c.HazPMDetails
))
{
_context.HazIds.Add(newHazId);
await _context.SaveChangesAsync();
return
RedirectToPage(
new
{ ptwNoId = newHazId.PTWNo });
}
if
(newHazId ==
null
)
{
return
NotFound();
}
return
RedirectToPage(
new
{ ptwNoId = newHazId.PTWNo });
}
However, after OnPost there is no data loaded. Can you help?
Reply
Answers (
7
)
image to binary convert from webcam capture in web c#
Why Can't I Get the Scoped Identity From EF After a Record is Saved?