I'm trying to use a input number in MVC, it accepts correctly the comma (I'm in a culture with a comma as a decimal separator) and MVC accepts it with the custom binder I made. The value is correctly saving in database, and comes back.
The problem is, when passing the decimal value, which looks like 0.231 to the number control, I guess it tries to format it to my culture with a comma and doesn't work, so nothing appears.
The binder works on return to server, but do I need something else on the return to the control for it to work on the return to the page?
My control in the razor view:
@Html.EditorFor(model => model.DecimalValueForExample, new { htmlAttributes = new { @class = "form-control", @type = "number", @step = "any", @min = "0.001", autocomplete = "off" } })
My attribute in the viewmodel:
[Display(Name = "DecimalValueForExample", ResourceType = typeof(Properties.Resources))]
[DisplayFormat(DataFormatString = "{0:0.###}", ApplyFormatInEditMode = true)]
[Range(0.001, double.MaxValue, ErrorMessageResourceName = "RangeErrorMessage", ErrorMessageResourceType = typeof(Properties.Resources))]
[Required]
public decimal DecimalValueForExample{ get; set; }
<input type="number" ...>works best with integers, not numbers with decimal fraction. Try it on w3schools: w3schools.com/html/html_form_input_types.asp