C
C#2y ago
Kurarin

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

61 Replies
Kurarin
Kurarin2y 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
Kurarin2y ago
well yeah but i think it might my sql statement or value input
Monsieur Wholesome
what?
Kurarin
Kurarin2y ago
Monsieur Wholesome
Explain what your problem is exactly What part is not working
Kurarin
Kurarin2y 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
Kurarin2y ago
dont think it does?
Monsieur Wholesome
Either Visual Studio would show a popup or the console would display sum
Kurarin
Kurarin2y ago
unless its connection string?? idk
Monsieur Wholesome
Does it say Data Saved Successfully?
Kurarin
Kurarin2y ago
lemme test that again , tough how u see viewbag.result lol
Monsieur Wholesome
Display ViewBag.Result in the cshtml somewhere
Kurarin
Kurarin2y ago
Kurarin
Kurarin2y ago
Kurarin
Kurarin2y ago
also slap me
Monsieur Wholesome
heh Anyhow, put a breakpoint on line 41 And check what it returns
Kurarin
Kurarin2y ago
hmmm i hit submit and
Kurarin
Kurarin2y ago
Kurarin
Kurarin2y 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
Kurarin2y ago
lmao it didnt
Monsieur Wholesome
dies
Kurarin
Kurarin2y ago
means it did even touch the getdetails not
Monsieur Wholesome
does your form contain a <button type="submit">?
Kurarin
Kurarin2y ago
input type =submit should i put button?
Monsieur Wholesome
what?
Kurarin
Kurarin2y 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
Kurarin2y ago
ok??
Monsieur Wholesome
ok?
Kurarin
Kurarin2y ago
method endpt? SaveDetails ah?
Kurarin
Kurarin2y ago
Kurarin
Kurarin2y ago
so naming
Monsieur Wholesome
Yep That's an endpoint
Kurarin
Kurarin2y ago
whenever i test it will say ended with code IntenseEyes
Monsieur Wholesome
Where does it say it?
Kurarin
Kurarin2y ago
Monsieur Wholesome
thats normal With my above changes, pressing the submit button, does it enter the method now?
Kurarin
Kurarin2y 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
Kurarin2y ago
Kurarin
Kurarin2y ago
Kurarin
Kurarin2y ago
Kurarin
Kurarin2y 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
Kurarin2y ago
Kurarin
Kurarin2y 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
Kurarin2y ago
run the project first?
Monsieur Wholesome
yes
Kurarin
Kurarin2y ago
Monsieur Wholesome
is that after pressing the button?
Kurarin
Kurarin2y ago
yeah
Monsieur Wholesome
Change the form action to only "/"
Kurarin
Kurarin2y ago
Kurarin
Kurarin2y ago
after changing formaction to /
Monsieur Wholesome
It doesnt hit the breakpoint, does it
Kurarin
Kurarin2y 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