I'm learning, and still getting used to, asp.net-mvc, and C#, and the 'T' version of SQL.
I have a database where I made one field DueDate
, data type Date
... and another field DueTime
, data type Time
in the .sql
file to create the table and seed it with some example entries.
But in my model.cs
, in C#, it seems there is only the DateTime
data type in C#?
But using that data type makes it so that in the View, you have to enter a date and a time for the DueTime
field, which is neither what I want, nor is it convenient or palatable for users.
I have searched the documentation, and googled for examples, and I can't seem to find any example similar enough to what I'm doing, that I could extrapolate something.
Here is the .sql
file to create & seed the table:
CREATE TABLE [dbo].[Homeworks] /* use plural db name */
(
[ID] INT IDENTITY (1,1) NOT NULL,
[Priority] NVARCHAR(18) NOT NULL,
[DueDate] DATE NOT NULL,
[DueTime] TIME(0) NOT NULL,
[Dept] NVARCHAR(4) NOT NULL,
[Course] NVARCHAR(9) NOT NULL,
[Assignment] NVARCHAR(64) NOT NULL,
[Notes] NTEXT NOT NULL,
CONSTRAINT [PK_dbo.Homeworks] PRIMARY KEY CLUSTERED ([ID] ASC)
);
INSERT INTO [dbo].[Homeworks] (Priority, DueDate, DueTime, Dept, Course, Assignment, Notes) VALUES
('super-important','2019-11-11','11:59:00', 'CS', '123', 'Questions/Answers', 'best to read ch 5 first'),
('meh','2019-11-18','11:59:00','CS','234','write helloWorld program','find out how to write a helloWorld program'),
('important','2019-11-13','11:59:00','MTH','123','chapter 3 problems','do the odd-numbered ones'),
('regular','2019-11-15','11:59:00','WR','101','write essay paper','figure out something to write an essay about'),
('notes','2019-11-14','11:59:00','CS','189','do up notes over chapters 1-5','make sure you know that crap for the mid-term')
GO
Here is the relevant section of the model class:
[Required]
[DisplayName("Due Date")]
public DateTime DueDate { get; set; }
//------------------------------------------------------------
[DisplayName("Due Time"), Required]
public DateTime DueTime { get; set; }
It all works, as in being functional when you run the page on localhost
-- as long as you enter the full date in the time
field. But input goes into the database as it should.
How do I get the form to accept simply the time, in the time
field? What data type to I use?