I am supplying a full DateTime located at model.StartDate in the following code:
@Html.DisplayFor(model => model.StartDate.ToString("hh:mm tt"),
CultureInfo.CreateSpecificCulture("hu-HU"));
My goal is to take the full DateTime
8/30/2012 11:33:48 AM
and display only
11:33:48 AM
however, I get the following error:
Templates can be used only with field access, property access,
single-dimension array index, or single-parameter custom indexer expressions.
Why is this error happening?
Note: I referenced this documentation to format my .ToString for my DateTime: http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx
You can put a DataAnnotation on your model class. Something like this -> [DisplayFormat(DataFormatString = "{0:d}", ApplyFormatInEditMode = true)].
Create a new property on your model that returns the formatted date.
Then use that property in your Razor markup