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
7 Replies
Why use Newtonsoft.Json
To clarify: this is not using Razor Pages
It's MVC with Razor views
Sorry, that’s what I meant.
Regardless, still stuck on this issue and cannot figure out why.
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 sentYeah it does, I've changed the code a bit and got it to hit the controller method now.
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)
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.