I am trying to figure out how to format a date using MVC3 RC2 and a model decorated with DataAnnotations.
This is my model ...
public class Model
{
[Display(Name = "Date of Birth")]
[DisplayFormat(@DataFormatString = "MM/dd/yyyy")]
public DateTime DateOfBirth { get; set; }
}
This is my controller ...
public class IndexController : Controller
{
public ActionResult Index()
{
return View( new Model() {DateOfBirth = DateTime.Now});
}
}
It's my opinion...
@model MvcApplication6.Models.Model
@Html.LabelFor(m=>m.DateOfBirth)
@Html.TextBoxFor(m => m.DateOfBirth)
@Html.EditorFor(m => m.DateOfBirth)
When I launch the site, for both controls the page displays a text box with the time included in the line, when all I want is the date (as indicated in the decorated property in the model).
I used the Brad Wilson article for ModelMetaData for this template.
Is it obvious what I'm doing wrong?
source
share