Click here to Skip to main content
15,895,667 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I am using the below code in MVC partial view to give an option for the user to select date?

@Html.DatePickerFor(m => m.ReasonData.ReasonModels[0].Ravi.BeginDate, new { @class = "RaviDate" })


and have the below code to control the format..

XML
var builder = new StringBuilder();
builder.Append(@"<script type='text/javascript'>$(document).ready(function () {
                            $('#");
builder.Append(controlId);
builder.Append(@"').datepicker({
                    showOn: 'button',
                    buttonImage: 'Content/Images/Correspondance/calendar.gif',
                    duration: 0,
                    changeMonth: true,
                    changeYear: true,
                    dateFormat:'mm/dd/yy'});
                });
                </script>");




for example when user selects the date, it would display it in the correct format which I wanted as 09/23/2014....

but if user goes to next page and come back to the previous page, it is displaying the date as 9/23/2014 12:00:00 AM, which is what I don't want....

This is how I have the model property defined..

C#
[Required(ErrorMessage = "A lapse date must be entered.")]
[DisplayName("When did the policy lapse?")]
[DisplayFormat(DataFormatString = "{mm/dd/yy}", ApplyFormatInEditMode = true)]
public DateTime? BeginDate { get; set; }




Please let me know how I can fix the date format?
Posted

1 solution

I believe it should be possible by specifying datetime format because HTML time element can retrieve time (i haven't tried it yet)

<time datetime="YYYY-MM-DDThh:mm:ssTZD">


Please try this URL
http://stackoverflow.com/questions/3734829/datetime-field-and-html-textboxfor-helper-how-to-use-it-correctly
 
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