Ryan
Ryan

Reputation: 31

Issues with Date Time in C#

Having some problems with adding Date Time to my project, i have a creation form that ask for the make, model, color, lisensePlate, and then Date Time. i have the drop down box that ask the user to click the date and then enter the time the vehicle was created. After entering a date ex(10.30.2017 3:00 PM) i get an error that says the date time was entered incorrectly. My Razor Index.cshtml is reference a models folder i created to add a search bar that will search all the makes of a vehicle in the database, i am not sure if that is conflicting with the date time or not. in my cars.cs model page i have date time written out like so

[Display(Name = "Date Time")]
[DataType(DataType.DateTime)]
public int DateTime { get; set; }

After speaking with my classmate he suggested we take an auto generator date time approach, where when the user enters all the vehicle information, and hits the create box, it will auto-generate the date time in the details page of the vehicle, to show the time the vehicle was entered. I am finding issues trying to do this too! :( any help would be great. if i 'am not explaining this well enough please let me know!

Upvotes: 0

Views: 289

Answers (1)

penleychan
penleychan

Reputation: 5470

What you have: public int DateTime { get; set; } is a type of integer. Change it to public DateTime DateTime { get; set; }

Upvotes: 3

Related Questions