Reputation: 41
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
Upvotes: 3
Views: 12245
Reputation: 9947
use this in your model definition for date
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
Upvotes: 9
Reputation: 19407
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")
Upvotes: 1