Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to take a time from user with separated drop down list. Is it efficieny code define date variables in drop down list item. Do i need to define separately it at my model like month,day,year. If i did this how can i save unified Date time format to my database.

What's is the best way code it ?
Posted
Comments
Nathan Minier 12-Aug-14 8:33am    
I would highly suggest using a Datepicker instead.

Use ModelBinders like i hope i will help you

VB
ModelBinders.Binders[typeof(DateTime)]  = new DateTimeModelBinder()
{
  Date = "Date", // Date parts are not splitted in the View
                 // (e.g. the whole date is held by a TextBox  with id "xxx_Date")
  Time = "Time", // Time parts are not  splitted in the View
                 // (e.g. the whole time  is held by a TextBox with id "xxx_Time")
  Day = "Day",
  Month = "Month",
  Year = "Year",
  Hour = "Hour",
  Minute = "Minute",
  Second = "Second"
};


for more details see this link

http://dariosantarelli.wordpress.com/2010/12/26/asp-net-mvc-2-splitting-datetime-in-drop-down-lists-and-model-binding/[^]
 
Share this answer
 
You can set a common date format in MVC like below
C#
[DisplayName("date of birth")]
   [DataType(DataType.Date)]
   [DisplayFormat(DataFormatString = "{dd/MM/yyyy}", ApplyFormatInEditMode = true)]
   public DateTime? Birth { get; set; }


Hope this helps
 
Share this answer
 

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