I have following decimal field:
[DisplayFormat(DataFormatString = "{0:n2}", ApplyFormatInEditMode = true)]
public decimal MyDecimal { get; set; }
In my Razor view
<td>Price</td>
<td>
@Html.EditorFor(model => model.MyDecimal, new { htmlAttributes = new { @class = "form-control decimal-small inline" } })
@Html.ValidationMessageFor(model => model.MyDecimal, "", new { @class = "text-danger" })
</td>
I want that users can only put a max of 2 number behind the decimal seperator. In many post I see that the DisplayFormat should work but it doesn't do anything in edit mode. In my edit field I can still put more than 2 numbers behind the seperator
I also tried
[DisplayFormat(DataFormatString = "{0:0.00}", ApplyFormatInEditMode = true)]
public decimal MyDecimal { get; set; }
Still no difference.