C
C#5mo ago
stayclaxxy

MVC w/ Razor View - Form POST

Hi All, I am trying to wrap my head around MVC in Razor pages, as I inherited some legacy stuff at work. I am trying to figure out why when I click my "submit" button on my Razor page, a blank page renders, and my breakpoint in my controller method for the post is never hit. What am I doing wrong? Relevant code: https://i.imgur.com/aUtf6YA.png
Imgur
7 Replies
The Fog from Human Resources
Why use Newtonsoft.Json
Angius
Angius5mo ago
To clarify: this is not using Razor Pages It's MVC with Razor views
stayclaxxy
stayclaxxyOP5mo ago
Sorry, that’s what I meant. Regardless, still stuck on this issue and cannot figure out why.
Angius
Angius5mo ago
I never used the Html.BeginForm() helper, but does it really point to this controller? Check what HTML gets generated there, see where the form acually points Also, check the network panel in devtools, to see where the form is sent and what is it that gets sent
stayclaxxy
stayclaxxyOP5mo ago
Yeah it does, I've changed the code a bit and got it to hit the controller method now.
stayclaxxy
stayclaxxyOP5mo ago
But seeing a different issue, If I keep line 34 in the razor view, my model comes in null to the controller method. However, if I comment line 34 out, It comes in populated with the Id and PostId (expected)
No description
stayclaxxy
stayclaxxyOP5mo ago
very odd. Figured it out using a forEach, the name of the variable inside of the forEach needs to match the parameter of the controller action.
Want results from more Discord servers?
Add your server