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 7748791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:52:26+00:00 2026-06-01T10:52:26+00:00

In ASP.NET MVC 4 Beta, I have an entity with this property: [DisplayFormat(DataFormatString =

  • 0

In ASP.NET MVC 4 Beta, I have an entity with this property:

[DisplayFormat(DataFormatString = "{0:o}", ApplyFormatInEditMode = true)]
public virtual DateTime SavedAt { get; set; }

In a view, generated with the “Controller with read/write actions and views, using EntityFramework” template, I have this code to create an editor for it:

<div class="editor-label">
    @Html.LabelFor(model => model.SavedAt)
</div>
<div class="editor-field">
    @Html.EditorFor(model => model.SavedAt)
    @Html.ValidationMessageFor(model => model.SavedAt)
</div>

Which produces this output:

<div class="editor-label">
    <label for="SavedAt">SavedAt</label>
</div>
<div class="editor-field">
    <input class="text-box single-line" data-val="true" data-val-date="The field SavedAt must be a date." data-val-required="The SavedAt field is required." id="SavedAt" name="SavedAt" type="text" value="2012-03-31T22:45:18.2244059" />
    <span class="field-validation-valid" data-valmsg-for="SavedAt" data-valmsg-replace="true"></span>
</div>

Notice that the date is formatted as “2012-03-31T22:45:18.2244059”.

If I replace the view code fragment with this:

@Html.HiddenFor(model => model.SavedAt)

This code is generated:

<input data-val="true" data-val-date="The field SavedAt must be a date." data-val-required="The SavedAt field is required." id="SavedAt" name="SavedAt" type="hidden" value="31/03/2012 22:45:18" />

Notice that the date is now formatted as “31/03/2012 22:45:18”.

The question is:

Is HiddenFor expected to honor the formatting defined by the DisplayFormat attribute?

If not, what would be a good alternative to have the hidden field output in the desired format?

  • 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-06-01T10:52:28+00:00Added an answer on June 1, 2026 at 10:52 am

    Is HiddenFor expected to honor the formatting defined by the DisplayFormat attribute?

    No, it doesn’t. Only the EditorFor and DisplayFor helpers use the DisplayFormat.

    If not, what would be a good alternative to have the hidden field
    output in the desired format?

    You shouldn’t really care about the format of a hidden field. It’s hidden, nobody sees it. But if for some reason you wanted a custom format you could override the default template with a custom editor template (~/Views/Shared/EditorTemplates/HiddenInput.cshtml):

    @if (!ViewData.ModelMetadata.HideSurroundingHtml)
    {
        @Html.Encode(ViewData.TemplateInfo.FormattedModelValue)
    }
    @Html.Hidden("", ViewData.TemplateInfo.FormattedModelValue)
    

    And then decorate your view model property with the [HiddenInput] attribute to indicate that you want this to render as a hidden field:

    [DisplayFormat(DataFormatString = "{0:o}", ApplyFormatInEditMode = true)]
    [HiddenInput(DisplayValue = false)]
    public virtual DateTime SavedAt { get; set; }
    

    And finally:

    @Html.EditorFor(x => x.SavedAt)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have recently upgraded my ASP.NET MVC application from beta to version 1. And
ASP.NET MVC 2 will support validation based on DataAnnotation attributes like this: public class
Hi, I have built a ASP.NET MVC website that uses Membership, this works fine.
I'm running ASP.NET MVC 2 Preview 2 (With VS 2010 Beta 2) using Entity
I have an ASP.NET MVC (Beta 1) website that I'm using themes with. When
I have ASP.NET MVC Beta on our web server running a few apps. My
I am running ASP.NET MVC Beta. I have an AJAX call running through jQuery
Does anyone have links to tutorials regarding the new IModelBinder in asp.net mvc beta?
is it possible to create something like this i ASP.NET MVC beta 1 i
I have an ASP.NET MVC (beta) application that I'm working on, and am having

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.