Introduction:
I have a WebMethod on my ASP.NET page which returns a Person object.
One of the fields is Birthday
Another way of tackling this problem is to make a new element in your person class and then use that. Example
public class Person {
public int Id {get;set;}
public string Name {get;set;}
public DateTime Birthday {get;set;}
public string BirthdayFormat { get {
return Birthday.toString("dd/MM/YYYY")
}}
}
I would have thought this would be the best way as then all the formating is in one place and where possible you can use.
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/YYYY}")]
Above the Birthday element, so that displayFor will use the correct formatting.