3

I have this model

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Text;
namespace PrototypeHelp.Models
{

    public class DocumentModel
    {   
        public int documentID { get; set; }
        public String Title { get; set; }
        public DateTime DateCreated { get; set; }
        public String Description { get; set; }
        public int authorID { get; set; }
        public String AuthorName { get; set; }
        public int categoryID { get; set; }
        public String Category { get; set; }
        public int topicID { get; set; }
        public String Topic { get; set; }
        [AllowHtml]
        public String DocumentBody { get; set; }
    }
}

I would like to display only the date using jquery but I cant get rid of the in "DateCreated".

Can anyone help me? I'm displaying it by using jquery

Hexie
  • 3,955
  • 6
  • 32
  • 55
dUnDoN
  • 41
  • 1
  • 1
  • 5

2 Answers2

9

use this in your model definition for date

[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
1

To display the date you can either decorate the property with a DisplayFormat attribute. This value is the format in which you want to display the date.

for example

public class DocumentModel
{
    [DisplayFormat(DataFormatString = "{0:yyyy/MM/dd}")]
    public DateTime DateCreated { get; set; }
    ...
}

or alternatively, in the view you can specify the format in the ToString() function.

@Model.DateCreated.ToString("yyyy/MM/dd")
Kami
  • 19,134
  • 4
  • 51
  • 63