hellogoodnight
hellogoodnight

Reputation: 2139

MVC5, Html input number, cannot set default decimal value

I am trying to set a default value for my number input tag. Here is the code:

<input id="discount-input" type="number" step="any" [email protected] />

Model.OrderDiscount is a decimal value, that holds 2,00. When I run the code, the input field is just blank. I tried another variable from Model, and that worked fine. That was an integer though, so I also hard coded value=2.00. I also tried all different combinations with step="0.01", step="0.1", step="1" and step="any" with the same result.

I know that you think that OrderDiscount just have to be empty, but no! I checked with the debugger 10 times. What is going on?

Edit: I tried another field on Model that also contained a decimal value. Neither this was displayed. It seems as I cannot use a variable to set a default decimal value.

Upvotes: 0

Views: 1883

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1039248

Try adding double quotes around the value and also make sure that your decimal separator is . instead of ,:

<input id="discount-input" type="number" step="any" value="@Model.OrderDiscount.ToString(CultureInfo.InvariantCulture)" />

Upvotes: 5

Related Questions