Click here to Skip to main content
15,892,965 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i am working on MVC3. in this project i am working with @Html.TextBoxFor(model=>model.Date)
i write a jquery function to select a valid date(in format dd/mm/yyyy), jquery datepicker working correct. but when tried to insert data into database, the data not being insert into database because
if(ModelState.Isvalid) getting false how can in do this to work correctly.
i am using entity framework (.edmx).

please help

Thanks in advance
Posted
Comments
Kumarbs 11-Aug-14 2:29am    
ModelState getting invalid means the datetime format is mismatching the required format. Ensure you are passing correct format.

1 solution

while passing datetime values to database you need to do
1. Pass the values in MM/DD/YYYY format
OR
2.Convert the dd/mm/yyyy format in sql query itself

so If you are passing date like then use casting :-
Cast('15-Aug-2014' AS DateTime)
 
Share this answer
 
Comments
Member 10371658 12-Aug-14 4:56am    
can you tell me the step for doing this. i tried a lot but i can't do this please help.
psima 3-Sep-14 3:57am    
CREATE TABLE testDateTime
(
id int not null,
OrderDate DateTime
)

insert into testDateTime values(1,'12/31/2013');
insert into testDateTime values(2,Cast('31-Dec-2014' AS DateTime));

Select * from testDateTime

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900