0

In my form I have a field to edit/create a decimal value.

@Html.TextBoxFor(m => m.prijs)

In my model, this property is declared as:

[Column(TypeName = "decimal(18,2)")]
[Display(Name = "Prijs")]
public decimal? prijs { get; set; }

Whatever I put in there, 12.5 or 12,5 or even 12.00 or 12,00 does not get accepted. Only "12" passes OK When I input in the DB manually "12,5" it saves without problems.

When I view the data in another view, I see the decimal value correctly.

What's happening here?

jps
  • 20,041
  • 15
  • 75
  • 79
JamesBB
  • 153
  • 1
  • 1
  • 7

1 Answers1

0

remove [Column(TypeName = "decimal(18,2)")] and try again.

  • Which database you are connecting? Could you share sample code where insertion takes place in your context? – Kenneth Korir Dec 22 '19 at 15:18
  • SqlServer But as stated, SQL server in itself does not have a problem with this. I guess it's a pure EF6 issue. – JamesBB Dec 22 '19 at 16:36
  • You might need to update your visual studio by running installer or update nugget library. Also try this solution https://stackoverflow.com/questions/3504660/decimal-precision-and-scale-in-ef-code-first. It may help when you define precision point using Fluent API for entity framework. – Kenneth Korir Dec 22 '19 at 18:22