1

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.

1 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.