?
Solved

how to format date with Html.TextBoxFor helper ?

Posted on 2010-01-12
4
Medium Priority
?
12,543 Views
Last Modified: 2013-11-08
how to format date which is displayed using  Html.TextBoxFor helper  class.
0
Comment
Question by:hariaspind
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 7

Expert Comment

by:jamesbaile
ID: 26294493
There are a number of ways you could do this.

You could create a DateTime editor template, which will mean that all dates are edited in the same way.

Have a look at the following which describes how to implement a jquery date picker.

http://elegantcode.com/2009/11/13/using-the-jquery-ui-datepicker-with-asp-net-mvc-2-templates/ 

0
 

Author Comment

by:hariaspind
ID: 26298017
I was trying to use the below syntax's.But the formatting is not working .  
 
<%= Html.TextBoxFor(model => model.ExpirationDate, String.Format("{0:MM/dd/yyyy}",
Model.ExpirationDate))%>


0
 
LVL 7

Accepted Solution

by:
jamesbaile earned 500 total points
ID: 26302484
The issue is that the String.Format("{0:MM/dd/yyyy}", Model.ExpirationDate) bit above is the TemplateName parameter of the TextBoxFor method. The view engine won't be able to find a template which matches the date.

What you need to do is decorate your model

[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM/dd/yyyy}")]
[DisplayName("Date Order Required")]
public DateTime DateRequired { get; set; }

and then use the following in your view

<%= Html.EditorFor(model => model.DateRequired)%>
0
 

Author Closing Comment

by:hariaspind
ID: 31676159
Thanks
0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question