If I have a decimal value in a field, and I am trying to display on a page, how do I format it (I would use string.format in web forms):
@Html.DisplayFor(Function(modelItem) String.Format("{0:n0}",currentItem.QualityM1))
That errors in VS2010 with the messae: Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions.
I wouldn't do this inside the view. It would be better to centralize this and provide this information as metadata as below:
public class Foo {
[DisplayFormat(DataFormatString = "{0:n0}")]
public decimal Bar { get; set; }
}
Then use this as usual:
@Html.DisplayFor(m => m.Bar)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With