Pallavi Sharma
Pallavi Sharma

Reputation: 41

How to do number formatting in mvc3 view

I want to get the output TotalAmount ( for example: 1000000000 as 1,000,000,000 ) but my code throws this error:

[ Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions. ].

Please give me solutions on my below context.

@Html.DisplayFor(modelItem => item.TotalAmount.ToString("#,##0.00"))

Upvotes: 2

Views: 2409

Answers (2)

Vinod Vutpala
Vinod Vutpala

Reputation: 843

You could try this one. ( it would handle even the nullable columns)

@Html.Raw(string.Format("{0:#,#.00}", Model.TotalAmount))

Upvotes: 0

Sirwan Afifi
Sirwan Afifi

Reputation: 10824

Model

[DisplayFormat(DataFormatString = "{0:0,0}")]
public virtual Decimal? TotalAmount{ get; set; }

View

Html.EditorFor(model => model.TotalAmount)

Upvotes: 3

Related Questions