2

I have an ASP.NET MVC application with a model with the following property:

[DisplayFormat(DataFormatString = "{0:N1}", ApplyFormatInEditMode = true)]
public List<decimal?> Scores { get; set; }

I was expecting it to be formatted with one decimal when printed like this:

@Html.EditorFor(p => p.ContainingModelList[i].Scores[j])

It is not. It shows two decimals no matter what. If I try to implement a dummy property like this, formatting works though:

[DisplayFormat(DataFormatString = "{0:N1}", ApplyFormatInEditMode = true)]
public decimal? Test { get; set; } 
// Test is later initalized with 1.35443M and rendered as "1.4"

So... does the DisplayFormat attribute in combination with EditorFor not support lists? Any way to work around it?

edit: I meant EditorFor, but wrote DisplayFor

Nilzor
  • 18,082
  • 22
  • 100
  • 167

0 Answers0