0

I'm currently stuck with a stupid problem, tried multiple solutions but it's still not working...

I'm currently on an ASP.NET MVC project and one of my classes needs a decimal as type so I created it like that : public decimal level { get; set; }

Then when I need to create a new object that contains this attribut , I use this on my view : <input type="number" name="level" step="any" min="1"/> I also tried with an editorFor but in both cases, I got this message :

The value '2.1' is not valid for level.

I've tried with 2.1 or 2,1 ( my culture is fr-FR) but both don't work and send the exact same error message... Can someone explains me why ?

Thanks in advance and have a nice day !

MrPixel6
  • 357
  • 1
  • 4
  • 19
  • Isn't the decimal separator for fr-FR a comma? – Fran May 06 '16 at 13:09
  • `2,1` is valid for you server, but if you have client side validation enabled, then you will get that error because jquery.validate validates a number based on a `.` for the decimal separator. You will need to reconfigure the validator or use [jquery.globalize](https://github.com/jquery/globalize) –  May 06 '16 at 13:10
  • @Stephen Muecke I have put `Html.EnableClientValidation(false);` on my page and it's still showing the same thing :s – MrPixel6 May 06 '16 at 13:13
  • If client side validation is disabled, then the form will submit and you will hit the controller POST method. If its still invalid, then it means that you server culture is one that does not accept `,` as the decimal separator. Are you sure its `fr-FR` in your `web.config.cs` file? –  May 06 '16 at 13:40
  • @StephenMuecke Yes I'm sure ! I just make more few test and now it's working with the client side validation off ;) Thx for helping me ! – MrPixel6 May 06 '16 at 13:52
  • Have a look at the answers [here](http://stackoverflow.com/questions/20263762/issue-with-decimals-commas-and-client-side-validation) for usage of `jquery.globalize` so that you can enable client side validation –  May 06 '16 at 14:03
  • @StephenMuecke I will check it later that would be useful ! Thank you again – MrPixel6 May 06 '16 at 14:04

1 Answers1

0

It should be 2.1M for decimal. You have to put the letter M after the number. If it was declared as float, it should have been 2.1F

Auguste
  • 2,007
  • 2
  • 17
  • 25