0

I try to display a decimal value.

// My Model

[DisplayFormat(DataFormatString = "{0:N2}", ApplyFormatInEditMode = true)]
public Decimal? Tax_percent { get; set; }

// My View (Try with EditorFor also)

<div class="form-group form-md-line-input form-md-floating-label no-hint">
<input type="number" name="Tax_percent" class="form-control@(!Model.Tenant.Tax_percent.HasValue ? "" : " edited")" value="@Html.DisplayFor(m => m.Tenant.Tax_percent)" step="0.01" min="0" max="100">
<label>@L("TaxPercent")</label>
</div>

The error message appear when i open my modal:

The specified value "0,00" is not a valid number. The value must match to the following regular expression: -?(\d+|\d+.\d+|.\d+)([eE][-+]?\d+)?" jquery.min.js:3

Thanks

Leonardo Henriques
  • 784
  • 1
  • 7
  • 22
  • 2
    You need to add some localization to your page. Take a look at this =>https://stackoverflow.com/questions/18218705/how-to-enable-jquery-validate-localization – CodeNotFound May 07 '18 at 10:06
  • Show you real code (`@Html.DisplayFor(m => m.Bar)` is not related to the property you have shown) –  May 07 '18 at 10:09
  • Sorry i change to my real code @Html.DisplayFor(m => m.Tenant.Tax_percent) – Franck Martin May 07 '18 at 10:24
  • @FranckMartin ASP.NET tries to parse text using the *browser's* language and the server's localization settings. That works perfectly for end users. If, like most developers, you set your user/system locale to US, you won't be able to parse non-US decimals without modifications – Panagiotis Kanavos May 07 '18 at 11:45
  • @FranckMartin you could hard-code the locale per site or page, if you are *certain* that all end users will use the same locale. You can do that with page directives or web.config settings. That will break if you have users from multiple countries though, especially for dates. That's why most forums have an option for end users to specify their preferred locale. – Panagiotis Kanavos May 07 '18 at 11:47

0 Answers0