class Report
{
[Display(Name = "Market Value")]
[DisplayFormat(DataFormatString = "£ {0:#,##0}", ConvertEmptyStringToNull = true)]
public int? MarketValue { get; set; }
}
Of course it works in the view and the result is "£ 10,000"
@Html.DisplayFor(model => report.MarketValue)
How can I retrieve the formatted value via server side with something like this?
string formattedValue = report.MarketValue.ToFormattedString();
Thanks in advance!
Very rough, but it can do the thing:
Usage: