C
Join ServerC#
help
Help with inserting data to database using web app C# VS
KKurarin2/15/2023

KKurarin2/15/2023
need help
KKurarin2/15/2023
shit is due in 12 hours before i have to submit
OOneWholesomeDev2/15/2023
once the submit button was clicked, it will run whatever function
HomeController.GetDetails()
isKKurarin2/15/2023
well yeah but
KKurarin2/15/2023
i think it might my sql statement or
KKurarin2/15/2023
value input
OOneWholesomeDev2/15/2023
what?
KKurarin2/15/2023

OOneWholesomeDev2/15/2023
Explain what your problem is exactly
What part is not working
What part is not working
KKurarin2/15/2023
ok when i submit the form , data should be inserted in the db but its not
OOneWholesomeDev2/15/2023
Does it throw an exception?
KKurarin2/15/2023
dont think it does?
OOneWholesomeDev2/15/2023
Either Visual Studio would show a popup or the console would display sum
KKurarin2/15/2023
unless its connection string?? idk
OOneWholesomeDev2/15/2023
Does it say Data Saved Successfully?

KKurarin2/15/2023
lemme test that again , tough how u see viewbag.result lol
OOneWholesomeDev2/15/2023
Display ViewBag.Result in the cshtml somewhere
KKurarin2/15/2023

KKurarin2/15/2023

KKurarin2/15/2023
also slap me
OOneWholesomeDev2/15/2023
heh
OOneWholesomeDev2/15/2023
Anyhow, put a breakpoint on line 41
OOneWholesomeDev2/15/2023
And check what it returns
KKurarin2/15/2023
hmmm i hit submit and
KKurarin2/15/2023

KKurarin2/15/2023
doesnt reacch
KKurarin2/15/2023
so does tat mean GetDetails() did not trigger?
OOneWholesomeDev2/15/2023
sus
OOneWholesomeDev2/15/2023
Put a break point at the very top of the function
OOneWholesomeDev2/15/2023
Does it hit that?
KKurarin2/15/2023
lmao it didnt
OOneWholesomeDev2/15/2023
dies
KKurarin2/15/2023
means it did even touch the getdetails
KKurarin2/15/2023
not
OOneWholesomeDev2/15/2023
does your form contain a <button type="submit">?
KKurarin2/15/2023
input type =submit
KKurarin2/15/2023
should i put button?
OOneWholesomeDev2/15/2023
what?
KKurarin2/15/2023
might be that lol i go test
KKurarin2/15/2023
didnt even
KKurarin2/15/2023

KKurarin2/15/2023
ngl its gonna be 1am for me
KKurarin2/15/2023
but watever
KKurarin2/15/2023
save me gdi
OOneWholesomeDev2/15/2023
Rename your method endpoint into
SaveDetails()
OOneWholesomeDev2/15/2023
Then head over to your form and make it
The button on the bottom of the form should look something like this:
<form action="/Home" method="POST">
</form>
The button on the bottom of the form should look something like this:
<form action="/Home" method="POST">
<input type="submit" value="Submit">
</form>
OOneWholesomeDev2/15/2023
@Kurarin
KKurarin2/15/2023
ok??
OOneWholesomeDev2/15/2023
ok?
KKurarin2/15/2023
method endpt?
KKurarin2/15/2023
SaveDetails ah?
KKurarin2/15/2023

KKurarin2/15/2023
so naming
OOneWholesomeDev2/15/2023
Yep
OOneWholesomeDev2/15/2023
That's an endpoint
KKurarin2/15/2023
whenever i test it will say ended with code 0
KKurarin2/15/2023

OOneWholesomeDev2/15/2023
Where does it say it?
KKurarin2/15/2023

OOneWholesomeDev2/15/2023
thats normal
OOneWholesomeDev2/15/2023
With my above changes, pressing the submit button, does it enter the method now?
KKurarin2/15/2023
doesnt even
KKurarin2/15/2023
go into the database
KKurarin2/15/2023
if it did , i wouldve seen it in
OOneWholesomeDev2/15/2023
Show me the top of your controller class
OOneWholesomeDev2/15/2023
And show me your cshtml form
KKurarin2/15/2023

KKurarin2/15/2023

KKurarin2/15/2023

KKurarin2/15/2023
ye some stuff are not working
OOneWholesomeDev2/15/2023
The stuff you have in your
You can move the meta tag in there though
<head>
doesnt belong there btw, it goes into the bodyYou can move the meta tag in there though
OOneWholesomeDev2/15/2023
Show me the submit button
KKurarin2/15/2023

KKurarin2/15/2023

OOneWholesomeDev2/15/2023
Open the Dev Tools in your browser
OOneWholesomeDev2/15/2023
Go to "Network"
OOneWholesomeDev2/15/2023
now click the submit button and see if you can find a red-highlighted entry in the network tab
KKurarin2/15/2023
run the project first?
OOneWholesomeDev2/15/2023
yes
KKurarin2/15/2023

OOneWholesomeDev2/15/2023
is that after pressing the button?
KKurarin2/15/2023
yeah
OOneWholesomeDev2/15/2023
Change the form action to only "/"
KKurarin2/15/2023

KKurarin2/15/2023
after changing formaction to /
OOneWholesomeDev2/15/2023
It doesnt hit the breakpoint, does it
KKurarin2/15/2023
doesnt
KKurarin2/15/2023
welp
KKurarin2/15/2023
unless this shit telling me to redo my whole form
KKurarin2/15/2023
:l
KKurarin2/15/2023
im too tired to type out all the crap
AAngius2/15/2023
One thing that comes to mind, is to use parameter binding
AAngius2/15/2023
Getting posted data from
HttpContext.Request
is some 2001 shitAAngius2/15/2023
Maybe, assuming you're using a decently-recent version of ASP, it can't see this action because it believes this action takes no parameters
AAngius2/15/2023
Parametric polymorphism and all that