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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:16:25+00:00 2026-05-16T11:16:25+00:00

Code: <% foreach (var item in Model) { %> <td> <%= Html.Encode(item.BirthDate) %> </td>

  • 0

Code:

  <% foreach (var item in Model) { %>   
  <td>
     <%= Html.Encode(item.BirthDate) %>
  </td>
  <% } %>

display this: 8/24/2009 12:00:00 AM but I need only date (8/24/2009). It is possible to do without any formating in controller action

  • 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-16T11:16:25+00:00Added an answer on May 16, 2026 at 11:16 am

    There are a couple of ways to go about it. If you’re using MVC 2, you could use a DisplayTemplate. Just put a DateTime.ascx file in the folder called /Views/Shared/DisplayTemplates and the line of code it would have in it is:

    <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<System.DateTime?>" %>
    <%: Model.HasValue ? Model.Value.ToShortDateString() : string.Empty %>
    

    (Note: if you use the <%: syntax then you don’t need the Html.Encode() because <%: does the HTML encoding for you – but that’s only if you’re using VS2010. If you’re using MVC 2 with VS2008, then stick with the Html.Encode() for this part) Then in your view you would simply do this:

    <%: Html.DisplayFor(m => m.BirthDate) %>
    

    That will change the format to only have the Date for all DateTime’s in your application. Of course you could put that directly in the view as well. But the DisplayTemplate will change it for all other DateTime’s as well and you won’t have to concern yourself with it in the view since it happens for your automatically.

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

Sidebar

Ask A Question

Stats

  • Questions 508k
  • Answers 508k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It looks like you generated the service and client configuration… May 16, 2026 at 4:19 pm
  • Editorial Team
    Editorial Team added an answer As an addition to the methods described here, as Robert… May 16, 2026 at 4:19 pm
  • Editorial Team
    Editorial Team added an answer It's the TextBoxFor helper method that's responsible for generating the… May 16, 2026 at 4:19 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have code like this: <% foreach (var item in Model) { %> <tr>
I have a Model that I can bind correctly for display purposes but I
When using an ASP.NET WebForms ListView control to display data in an HTML table
With this code I have error: Object reference not set to an instance of
i updated code and this is the corect solution of problem [AcceptVerbs(HttpVerbs.Post)] public ActionResult
I'm trying to build a Editable GridView like control (Order column) with this code
I guess this is a noob question, but here it comes: I have a
this is my code I have: I have read that setting up the CommandText
I would like to render a list of HTML links in ASP.NET MVC. Note
ASP.NET MVC 2 has powerful features for generating the model-dependent content of the Edit

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.