Asp.net mvc: thousands separator for int value

I have a price field in my database as a whole. Now I pass my model to view and view the price:

@Html.DisplayFor(modelItem => item.price) 

How can I place a thousand dividers at a price? Tnx

+6
source share
2 answers

Apply the DisplayFormat attribute to the model property:

 [DisplayFormat(DataFormatString = "{0:N2}")] public decimal Cost { get; set; } 

Formatting is then done using ModelBinder for you, not so that you can remember it in each individual view.

+6
source

Here...

 @Html.DisplayFor(modelItem => item.price.ToString("n2")) 
+2
source

Source: https://habr.com/ru/post/970570/


All Articles