I have added the following model class inside my asp.net MVC core web application 3.1:-
[ModelMetadataType(typeof(Submission_Validation))]
public partial class Submission
{
}
and the following Submission_Validation
class:-
public class Submission_Validation
{
[DisplayFormat(ApplyFormatInEditMode = true,
DataFormatString = "{0:dd MMMM yyyy hh:mm:ss tt}")]
public DateTime Created { get; set; }
}
now if i show the Created
field using @Html.DisplayFor(model => model.Created)
the date will have the correct format as specified inside the data annotation, but if i render the value inside the MVC-6-Grid ( https://mvc6-grid.azurewebsites.net/) as follow:-
@(Html
.Grid(Model)
.Build(columns =>
{
columns.Add(model => model.Created).Titled("Created")
})
.Using(GridFilterMode.Header)
.Empty("No data found")
.Filterable()
.Sortable()
.Pageable(pager =>
{
pager.RowsPerPage = 250;
})
the date will ignore the data annotation specified. any idea how i can fix this?
You can format it in the Grid:
columns.Add(model => model.Created).Titled("Created").Formatted("{0:dd MMMM yyyy hh:mm:ss tt}");