C
C#4mo 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
Angius4mo ago
To clarify: this is not using Razor Pages It's MVC with Razor views
stayclaxxy
stayclaxxy4mo ago
Sorry, that’s what I meant. Regardless, still stuck on this issue and cannot figure out why.
Angius
Angius4mo 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
stayclaxxy4mo ago
Yeah it does, I've changed the code a bit and got it to hit the controller method now.
stayclaxxy
stayclaxxy4mo 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
stayclaxxy4mo 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