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

  • SEARCH
  • Home
  • 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 6002563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:59:46+00:00 2026-05-23T00:59:46+00:00

I have an edit object view. In this view are several DateTime? properties that

  • 0

I have an edit object view. In this view are several DateTime? properties that are using:

model.MyDateTime ) %>

I have an editor template named DateTime that is strongly typed against a DateTime? type. The view is declared as follows:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<DateTime?>" %>

<% if( Model.HasValue ) { %>
    <%= Html.TextBoxFor( x => Model, Model.Value.ToShortDateString() ) %>
<% } else { %>
    <%= Html.TextBoxFor(x => Model) %>
<% } %>

The time portion is always displayed no matter what I do. I know the display template is being rendered. I’ve added static text for the if output as well as the else output and the former always shows. The incredibly odd thing is I can do:

<%= Html.Encode(Model.Value.ToShortDateString())   %>

And no time portion is displayed. I’m rather stumped. Below are the GET & POST actions I am using:

   public ActionResult EditAssociate(int? Oid)
    {
        if (!Oid.HasValue)
            return RedirectToAction("SelectReviewYearAndAssociate");
        MpaNonExemptData mpaNonExemptRecord = repository.getNonExemptDataByOid(Oid.Value);
        return View(mpaNonExemptRecord);
    }

[HttpPost]
public ActionResult EditAssociate(MpaNonExemptData associate)
{
    repository.updateNonExemptDataByOid(associate);
    return View(associate);
}

As you can see, it’s really straightforward. Any thoughts?

I have looked at the following questions, but did not find an answer:

TextBoxFor Date object always shows time element

TextBoxFor Helper retains previous value even when model value is empty

  • 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-23T00:59:47+00:00Added an answer on May 23, 2026 at 12:59 am

    You should use the TextBox helper inside your editor template as contrary to TextBoxFor it allows you to specify the value (the second argument of the TextBoxFor helper does not do what you think it does => it’s simply used to pass html attributes to the generated field, not to set the value):

    <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<DateTime?>" %>
    
    <% if(Model.HasValue) { %>
        <%= Html.TextBox("", Model.Value.ToShortDateString()) %>
    <% } else { %>
        <%= Html.TextBox("") %>
    <% } %>
    

    Also if this is an editor template (which is what it seems to be) you need to include it with Html.EditorFor(x => x.MyDateTime) instead of Html.DisplayFor(x => x.MyDateTime) as shown in your example.

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

Sidebar

Related Questions

I have several objects in the database. Url to edit an object using the
Edit: I have solved this by myself. See my answer below I have set
EDIT: I have submitted a bug report and Microsoft have acknowledge that it is
I have recently been working with Python using Komodo Edit and other simpler editors
I have a data-structure (in plist) that looks something like this: What i have
EDIT: I have added Slug column to address performance issues on specific record selection.
What are extension methods in .NET? EDIT: I have posted a follow up question
have downloaded Orca to edit an MSI file. I want to remove some banner
EDIT: I also have access to ESXLT functions. I have two node sets of
I have found a few libraries to edit MP3 tags (UltraID3Lib is great) but

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.