Question

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 :)

Was it helpful?

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.

OTHER TIPS

In version 2 of MvcContrib its Grid ignored both DisplayFormat and DisplayName attributes. And it is fixed in version 3.0.51.0 - see this: http://mvccontrib.codeplex.com/workitem/7064

I have checked this and it works properly now (even if the columns are not auto-generated).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top