3

Currently, when applying the DataAnnotation Currency to a property, it then using DisplayFor renders this as the html :

cshtml:

<div>@Html.DisplayFor(m=>m.Price)</div>

html:

<div>$U 4.193,99</div>

How can I change it so the currency symbol is not white-spaced? I know I can apply a css to the div for white-space:nowrap; but it would be better if I can just change the currency string format to get :

<div>$U&nbsp;4.139,99</div>
Bart Calixto
  • 19,210
  • 11
  • 78
  • 114

2 Answers2

3

You can use a custom display format (instead of the "Currency" attribute):

[DisplayFormat(DataFormatString = "$U&nbsp;{0:#,###0.00}")]

Example: http://rextester.com/PQSV4120 (Note that the "nbsp;" text is removed when the example code saves. You can manually put it back in though, and re-run it.)

EDIT: Changed format string and added example.

htxryan
  • 2,871
  • 2
  • 21
  • 21
1

Use this annotation: [DisplayFormat(DataFormatString = "{0:0}")]

Matrix
  • 125
  • 2
  • 6