❔ Why isn't my form being submitted?
As far as I can see, my form is not being submitted because the HabitType is null (there must be something wrong with the section and option tags but I can't tell)
Basically, the user is supposed to log their habits through a form which will insert the values into the database.
Select and option tags will make the user choose which kind of habit he will log (the HabitLog class contains a HabitType property), the foreach loop will loop through each habit type which exists. The other two ones are for the user to log the date and quantity. Appreciate any help!
LogHabit.cshtml:
https://pastebin.com/CFusfz41
LogHabit.cshtmlcs:
https://pastebin.com/JED3jAMP
HabitLog class:
https://pastebin.com/CJ1HK88K
HabitType class:
https://pastebin.com/Ly8Qtg0i
Pastebin
@page@model MVC.HabitTracker.Pages.LogHabitModel@{}Log a habit
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Pastebin
using Microsoft.AspNetCore.Mvc;using Microsoft.AspNetCore.Mvc.Razor...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Pastebin
using System.ComponentModel.DataAnnotations;namespace MVC.HabitTrac...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Pastebin
using System.ComponentModel.DataAnnotations;namespace MVC.HabitTrac...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
20 Replies
Any errors?
Also, you seem to be inserting everything into the
habit_logs
table. Shouldn't there be a foreign key to habit_types
or some such?
I guess we'll never know
Cyano
I don't think you have an implicit conversion operator from
HabitType
to any integer or anything
Make sure the generated HTML actually looks correctWell there's your problem, then
I don't get why is the @HabitType being displayed like that though
Because that's how types are displayed by default
As their fully-qualified name
That's the default behaviour of
ToString()
method of the Object
classbut if it's always the same then it's the same object all the time right?
So you either need to override that behaviour
Or use the ID or something as your value
Yes, it's dependent on the type, not the given instance
Angius
REPL Result: Success
Console Output
Compile: 624.743ms | Execution: 53.882ms | React with ❌ to remove this embed.
As demonstrated
what would you advice me to do if I want to select the object (habitType) to use it later like this? tableCmd.CommandText =
@$"INSERT INTO habit_logs(ImagePath,
Name,
UnitOfMeasurement,
Date,
Quantity) VALUES('{HabitLog.HabitType.ImagePath}', '{HabitLog.HabitType.Name}', '{HabitLog.HabitType.UnitOfMeasurement}', '{HabitLog.Date}', {HabitLog.Quantity})";
Well, the value of the option should be the thing you will want to use
If you were to actually use the "relational" part of "relational database", an ID would be what you want
like, selecting the id and then getting the habit through the id with c#?
Like getting the ID and saving it in the habit, as a foreign key to habit type
A classic one-to-many relationship
alright, will try bro, thank you for your help and sorry if i have a bit of trouble understanding you, I'm new to razor pages
This has nothing to do with Razor Pages, but rather with relational databases
yeah I'm still a beginner in sql too
Well, google around, learn about the "relational" part of "relational database", and come back should you have more issues
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.