问题
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 4.139,99</div>
回答1:
You can use a custom display format (instead of the "Currency" attribute):
[DisplayFormat(DataFormatString = "$U {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.
回答2:
Use this annotation: [DisplayFormat(DataFormatString = "{0:0}")]
来源:https://stackoverflow.com/questions/18523145/change-how-datatype-currency-renders-html