Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3961844
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:01:31+00:00 2026-05-20T03:01:31+00:00

I am trying to override the DateTime template since I need custom class names

  • 0

I am trying to override the DateTime template since I need custom class names on it.

So I have this in my edittemplates/datetime.cshtml

@model System.DateTime

@Html.TextBox("", Model, new { @class = "date-picker" })

// in my view model

  [DataType(DataType.Date)]
  public DateTime Date { get; set; }

So I am not sure how to make it just use my meta tag and use the date only. Yes I could hardcode it in and have Mode.ToShortDate() but maybe I will want ToLongdate() one time.

Edit

I think people are getting confused. First ignore the class name I just threw it in their to show why I am overriding the default datetime.

For me hardcoding these class names don’t seem like a solution to me and that why I am struggling to figure out if I really want to use these templates and instead just go back to a using textboxfor().

The problem with that is then I have to change “Date” to a string as I only want to show the “Date” part. So now I have to later on convert the string back to a datetime so I can insert it into my db. With the templates I could leave it as a datetime and save a conversion.

For me it is weird to think that every datetime one will need the same class names and same html properties. These editorFor() should really take in html properties.

Second my whole post was this.

If I don’t override the datetime template and do this

  [DataType(DataType.Date)]
  public DateTime Date { get; set; }

then the rendered result will only show the date part. Now if I override the datetime so I can add my custom stuff to it and do what I have above it will not respect the meta tag and will render the full datetime.

So my question is how do I make it so it uses the meta tag? Since not every date field that I have will only show the date. So hard coding something like that into the template would be dumb.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T03:01:32+00:00Added an answer on May 20, 2026 at 3:01 am

    I have just recreated your example and it appears to work as expected.

    In your View are you binding the Date property as normal?

    @Html.EditorFor(model => model.Date)
    

    If you have this then it should work as you want it to. However if it still isn’t working then I can only think of trying one other thing. On your model add the following attribute;

    [UIHint("ToLongDate")]
    public DateTime Date { get; set; }
    

    Then create a new PartialView in your edittemplates folder called ToLongDate.cshtml and add the following lines;

    @model System.DateTime
    @Html.TextBox("", Model.ToLongDateString(), new { @class = "date-picker" })
    

    Using this technique you could create various date format varitations and have each property using different ones.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to override the DataGridViewTextBoxCell's paint method in a derived class so
I am trying to design a model in which I have a List of
I'm trying to override Ant compiler attributes via the command line so that all
I'm trying to find documentation on how I can override a property name in
Trying to get my css / C# functions to look like this: body {
Trying to keep all the presentation stuff in the xhtml on this project and
I'm trying to create a timer which updates a label every tick, This is
I have a class that has an enum type indicating whether the message type
I am trying to override the default behaviour of an anchor tag so i
I'm trying to override the mousewheel control so that when the mouse wheel is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.