I have a price field in my database as integer now i pass my model to view and show the price in view:
@Html.DisplayFor(modelItem => item.price)
How can i put thousand separator for price in view? tnx
Apply the DisplayFormat
attribute to your model property:
[DisplayFormat(DataFormatString = "{0:N2}")]
public decimal Cost { get; set; }
Then the formatting is done by the ModelBinder for you instead of you having to remember to do it in each individual view.
Here ...
@Html.DisplayFor(modelItem => item.price.ToString("n2"))
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