Skip to content
Loading
ASP.NET Core Razor Page OnPost with parameter
  • Marius Vasile
    Ok Sachin, I have the following error
     
    An unhandled exception occurred while processing the request.
    SqlException: The INSERT statement conflicted with the FOREIGN KEY constraint "FK_HazIds_OrgPTWs_PTWNo". The conflict occurred in database "aspnet-RoSafety-53bc9b9d-9d6a-45d4-8429-2a2761773502", table "dbo.OrgPTWs", column 'PTWNo'.
     
    The statement has been terminated.
     
    This means I am not passing ptwNoId as PTWNo in the sql. I used the below line to get it
    1. for="HazId.PTWNo" value="@Html.HiddenFor(model => model.OrgPTW, new { Value = "@OrgPTW.PTWNo" })" />  
    How do I pass ptwNoId to HasId.PTWNo please
  • Marius Vasile
    Maybe I was not very clear when I ask the question, sorry for that. On page load, OnGet gets an id ptwNoId from another page, actualy, is a redirect from another page and sho it on the page. after getting that id, ptwNoId, this is used for any data uploaded, is the main id. But after OnPost, I want the page to load and show the uploaded value. instead, ptwNoId is no longer shown and no data. How do I get the page to be reloaded using the same ptwNoId?
  • Mageshwaran R
    Hi Marius,
    try this link,
    https://www.learnrazorpages.com/razor-pages/model-binding 
  • Marius Vasile
    OnPost is not a problem, or maybe it is, but Redirect and OnGet after the OnPost is. I don't understand why I should pass the class name as parameter, be more specific please