0

In my model:

[Range(1, 100)]
[DataType(DataType.Currency)]
[Column(TypeName = "decimal(18, 2)")]
public decimal MyDecimal { get; set; }

In my cshtml file:

<input asp-for="MyModel.MyDecimal" class="form-control" step="0.01" type="number" value="0.00" />

It's not working: The value is not a number.

Magnetron
  • 7,495
  • 1
  • 25
  • 41
Martin VU
  • 97
  • 6

1 Answers1

2

In my model:

public decimal MyDecimal { get; set; }
[Range(1, 100)]
[DataType(DataType.Currency)]
[Column(TypeName = "decimal(18, 2)")]
public string MyDecimal_string { get; set; }

In my .cshtml file:

<input asp-for="MyDecimal_string" step="0.01" type="number" class="form-control" />

In my .CS file, I convert MyDecimal_string to decimal:

Mydecimal = decimal.Parse(MyDecimal_string, CultureInfo.InvariantCulture);

I am using .NET 5

Martin VU
  • 97
  • 6