Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi to all,

here i'm set a field name startdate in textbox but the date format will takes(MM:DD:YYYY) now i want to change (DD:MM:YYYY).can anybody help for this task.

in modal:

[DataType(DataType.Date)] [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)] public Nullable<system.datetime> Start_date { get; set; }

IN VIews:-

@Html.TextBoxFor(m => m.Start_date, "{0:dd/MM/yyyy}")
Posted
Updated 25-Jul-14 19:07pm
v2

1 solution

@Html.TextBoxFor(m => m.Start_date, new { Value = Model.Start_date.ToString("dd-MM-yyyy"), id = "MySuperCoolId"});
 
Share this answer
 
Comments
JOTHI KUMAR Member 10918227 26-Jul-14 1:56am    
thanks for reply i got error NullReferenceException Class
Praveen Dselva 26-Jul-14 2:02am    
Check, is your date is nullable or not
JOTHI KUMAR Member 10918227 26-Jul-14 2:13am    
it is nullable
Praveen Dselva 26-Jul-14 2:22am    
this is the reason, date never set nullable
it can be default 1/1/1 or 1/1/1970 as required.

this is the reason you got NullReferenceException
JOTHI KUMAR Member 10918227 26-Jul-14 2:29am    
in modal
[Required(ErrorMessage = "Start Date is required.")]
[Column(TypeName = "date")]
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:DD/MM/yyyy}")]
public DateTime Start_Dte { get; set; }

in view:
@Html.TextBoxFor(model => model.Start_Dte, new { Value = Model.Start_Dte.ToString("dd-MM-yyyy"), id = "text" });
this my code tell if its correct or not

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