C
C#2y ago
Kurarin

Help with inserting data to database using web app C# VS

61 Replies
Kurarin
KurarinOP2y ago
need help shit is due in 12 hours before i have to submit
Monsieur Wholesome
once the submit button was clicked, it will run whatever function HomeController.GetDetails() is
Kurarin
KurarinOP2y ago
well yeah but i think it might my sql statement or value input
Monsieur Wholesome
what?
Kurarin
KurarinOP2y ago
Monsieur Wholesome
Explain what your problem is exactly What part is not working
Kurarin
KurarinOP2y ago
ok when i submit the form , data should be inserted in the db but its not
Monsieur Wholesome
Does it throw an exception?
Kurarin
KurarinOP2y ago
dont think it does?
Monsieur Wholesome
Either Visual Studio would show a popup or the console would display sum
Kurarin
KurarinOP2y ago
unless its connection string?? idk
Monsieur Wholesome
Does it say Data Saved Successfully?
Kurarin
KurarinOP2y ago
lemme test that again , tough how u see viewbag.result lol
Monsieur Wholesome
Display ViewBag.Result in the cshtml somewhere
Kurarin
KurarinOP2y ago
Kurarin
KurarinOP2y ago
Kurarin
KurarinOP2y ago
also slap me
Monsieur Wholesome
heh Anyhow, put a breakpoint on line 41 And check what it returns
Kurarin
KurarinOP2y ago
hmmm i hit submit and
Kurarin
KurarinOP2y ago
Kurarin
KurarinOP2y ago
doesnt reacch so does tat mean GetDetails() did not trigger?
Monsieur Wholesome
sus Put a break point at the very top of the function Does it hit that?
Kurarin
KurarinOP2y ago
lmao it didnt
Monsieur Wholesome
dies
Kurarin
KurarinOP2y ago
means it did even touch the getdetails not
Monsieur Wholesome
does your form contain a <button type="submit">?
Kurarin
KurarinOP2y ago
input type =submit should i put button?
Monsieur Wholesome
what?
Kurarin
KurarinOP2y ago
might be that lol i go test didnt Smoge its gonna be 1am for me but watever save me gdi
Monsieur Wholesome
Rename your method endpoint into SaveDetails() Then head over to your form and make it
<form action="/Home" method="POST">

</form>
<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>
<form action="/Home" method="POST">

<input type="submit" value="Submit">
</form>
@Kurarin
Kurarin
KurarinOP2y ago
ok??
Monsieur Wholesome
ok?
Kurarin
KurarinOP2y ago
method endpt? SaveDetails ah?
Kurarin
KurarinOP2y ago
Kurarin
KurarinOP2y ago
so naming
Monsieur Wholesome
Yep That's an endpoint
Kurarin
KurarinOP2y ago
whenever i test it will say ended with code IntenseEyes
Monsieur Wholesome
Where does it say it?
Kurarin
KurarinOP2y ago
Monsieur Wholesome
thats normal With my above changes, pressing the submit button, does it enter the method now?
Kurarin
KurarinOP2y ago
doesnt even go into the database if it did , i wouldve seen it in
Monsieur Wholesome
Show me the top of your controller class And show me your cshtml form
Kurarin
KurarinOP2y ago
Kurarin
KurarinOP2y ago
Kurarin
KurarinOP2y ago
Kurarin
KurarinOP2y ago
ye some stuff are not working
Monsieur Wholesome
The stuff you have in your <head> doesnt belong there btw, it goes into the body You can move the meta tag in there though Show me the submit button
Kurarin
KurarinOP2y ago
Kurarin
KurarinOP2y ago
Smoge
Monsieur Wholesome
Open the Dev Tools in your browser Go to "Network" now click the submit button and see if you can find a red-highlighted entry in the network tab
Kurarin
KurarinOP2y ago
run the project first?
Monsieur Wholesome
yes
Kurarin
KurarinOP2y ago
Monsieur Wholesome
is that after pressing the button?
Kurarin
KurarinOP2y ago
yeah
Monsieur Wholesome
Change the form action to only "/"
Kurarin
KurarinOP2y ago
Kurarin
KurarinOP2y ago
after changing formaction to /
Monsieur Wholesome
It doesnt hit the breakpoint, does it
Kurarin
KurarinOP2y ago
doesnt welp unless this shit telling me to redo my whole form :l im too tired to type out all the crap
Angius
Angius2y ago
One thing that comes to mind, is to use parameter binding Getting posted data from HttpContext.Request is some 2001 shit 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 Parametric polymorphism and all that
Want results from more Discord servers?
Add your server