locked
Default validation of "float" fields fails with "The field FieldName must be a number." RRS feed

  • Question

  • Hi,

    I will try to keep this question short.

    I am diving into EF 4.1 and Database First approach using MVC 3 but are running into validation problems. The fields in one of my test tables is using "float" to store floating point numbers. When i create a controller and views to manipulate my model, i get the error "The field FieldName must be a number", and it seems to only accept Integer values.

    Am I missing something here? Do I need to somehow create custom validators for even basic data types as float?

    // Mikael

    Sunday, June 26, 2011 6:35 PM

Answers

  • Hi Jackie,

    Sorry that I forgot to update this forum thread last night.

    I managed to work out what the problem was last night with some help from the forums in ASP.net. You are 100% correct when you say it is a culture problem. But it is not a mixup between client and server culture in this case, but seems to be a bug in the jQuery validation API regarding culture and locales. Both my server and client are setup for "swedish", but for some reason the jQuery validation mixes it up. "," and "." both do not work and I then end up with the validation always saying that the entered data is not valid. Most likely, the client-side validation denies one, and server-side validation denies the other.

    I did a workaround on this by loading german methods in the jQuery, but will also register a case at jQuery to follow this up.

    All in all, it turns out to be a MVC / jQuery problem and not related to EF.

    // Mikael


    • Marked as answer by MB1972 Wednesday, June 29, 2011 7:59 AM
    Wednesday, June 29, 2011 7:59 AM

All replies

  • I have spent some time trying to figure out what the problem is and it seems to be more a jQuery validation problem then an EF problem. But if someone can confirm that creating a basic EF project, using Database first and the ADO.NET DbContext Generator in MVC 3, creates these kind of issues, it would be much appreciated.

     

    Sunday, June 26, 2011 8:42 PM
  • Hello Mikael,

    As far as I know, the float type in database mapped to class using EF is Double type. And I think may be the reason is just like this thread said, http://stackoverflow.com/questions/4680641/why-is-asp-net-mvc-3-not-validating-my-floats-correctly is that the client-side validation culture is different from server side validation culture.

    You could refer to the given solution in the above thread. I hope this can help you.

    If you have any questions or feedbacks, please feel free to let us know.

     

    Have a nice day,

     


    Jackie Sun [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, June 29, 2011 7:13 AM
  • Hi Jackie,

    Sorry that I forgot to update this forum thread last night.

    I managed to work out what the problem was last night with some help from the forums in ASP.net. You are 100% correct when you say it is a culture problem. But it is not a mixup between client and server culture in this case, but seems to be a bug in the jQuery validation API regarding culture and locales. Both my server and client are setup for "swedish", but for some reason the jQuery validation mixes it up. "," and "." both do not work and I then end up with the validation always saying that the entered data is not valid. Most likely, the client-side validation denies one, and server-side validation denies the other.

    I did a workaround on this by loading german methods in the jQuery, but will also register a case at jQuery to follow this up.

    All in all, it turns out to be a MVC / jQuery problem and not related to EF.

    // Mikael


    • Marked as answer by MB1972 Wednesday, June 29, 2011 7:59 AM
    Wednesday, June 29, 2011 7:59 AM