mvccontrib-grid

Html.Grid DisplayFormat data annotation does not work


I am trying to bind my view model to the Html.Grid. I have set the DisplayFormat annotation to one of my property. However, the format is not applied when the grid is rendered.

Here's the code: In view model:

[DisplayFormat(DataFormatString = "{0,10:###,0}")]
public double AmountCurrency { get; set; } 

On aspx:

    <%= Html.Grid<MyViewModel>(Model.MyViewModel)
            .Columns( column => {
             column.For(x => x.AmountCurrency);
...

When I format it in the aspx it works:

column.For(x => x.AmountCurrency).Format("{0,10:###,0}");

Not sure why it doesn't work with Data Annotation.

Any help is greatly appreciated.

Thanks :)


Solution

  • From looking at the Docs and Jeremy Skinner's comment, I think this only works with Auto-generated columns.

    If auto-generated columns don't work, then a custom grid renderer might be the way to go.