Webgrid Format of datetime and setting style

Bayrat picture Bayrat · Mar 31, 2011 · Viewed 13.9k times · Source

I'm struggline with syntax gremlins with the WebGrid. In my normal razor markup i format a date inside my foreach like so

<td>
        @String.Format("{0:MM/dd/yy hh:mm:ss}", item.complianceedatetime)
    </td>

and I set my column width like so

<th width="150px">
        Download Date/Time
    </th>

How would I do this with the Grid.Column syntax

grid.Column("complianceedatetime", "Download Date/Time", ?, ?)

Answer

wtjones picture wtjones · Aug 28, 2011
@grid.GetHtml(
    column: grid.Columns(
              grid.Column("Complianceedatetime", "Download Date / Time", 
format: @<text>@item.complianceedatetime.ToString("MM/dd/yy hh:mm:ss")</text>)
            )
)

I know this works because I have this exact code in my project:

grid.Column(
            "PublishDate",
            canSort: true,
            format: @<text>@item.PublishDate.ToString("MM/dd/yyyy")</text>
        ),