asp.net-mvc-3datetimemvccontrib

Show date format only and keep sorting AZ in MVCContrib Grid


I use the following LINQ to create grid model:

...
            var query = from a in GetUser()
                        select new UserModel
                        {
                            ID = a.ID,                            
                            StartDate = a.StartDate,
                            EndDate = a.EndDate,
                            StateName = a.State.StateName,
                            StateID = a.StateID,
                            City = a.City,
                        };
            return query;
  ....

and the HTML is

 @Html.Grid(Model.PagedList).Columns(
                        col =>
                        {
                            col.For(c => c.StateName).Named("State").Attributes(@class => "row").HeaderAttributes(@class => "head");
                            col.For(c => c.City).Named("City").Attributes(@class => "row").HeaderAttributes(@class => "head");
                            col.For(c => c.StartDate).Named("Start Date").Attributes(@class => "row").HeaderAttributes(@class => "head");
                            col.For(c => c.EndDate).Named("End Date").Attributes(@class => "row").HeaderAttributes(@class => "head");
                            col.For(c => Html.ActionLink("Details", "Details", new { id = c.ID })).Named("View Details").HeaderAttributes(@class => "head").DoNotEncode();
                        }).Sort(Model.GridSortOptions).Attributes(@class => "grid") 

The main problem is how to show only DATE without TIME part?

I tried some options but in some cases I got the errors and in other cases sorting AZ doesn't work at all.

Any clue? Thank you!!!


Solution

  • Try using

    col
    .For(c => c.EndDate.ToLongDateString())
    .Named("End Date")
    .Attributes(@class => "row")
    .HeaderAttributes(@class => "head");