Wednesday 15 August 2012

c# - Range for int treated as string -


I have a project in C #, MVC4 EF (data first).

In my scene view I have several numerical fields, for which I want to specify the values ​​allowed using range. For some strange reasons, my numbers are considered as strings, which spoil the verification.

For example, take the "length in" field: This is an integer in the database.

My view I have the code:

  @ Html.EditorFor (model => model.LengthInch) @ HTML.ValidationMessageFor (model => model. LengthInch)   

And finally in my metadata file (for model) I have the code:

  [range (0, 11, error message) "{0} must be between {1}} and {2}.")] Public Nullable & lt; Int & gt; Get the length {in; Set; }   

If I enter 0, 1, 10 or 11 in the field, everything is very good but if I enter 2 for example, I get a verification error. "For the length, the value should be between 0 and 11" goes to the same 3 to 9. It seems that for some reason the numbers are considered as strings. Michael's "new" project work point me in the right direction, which I do not know? Thanks! It seems that jquery.validate people had pushed a bug precisely that was addressed. Type = "date" and others should be compared to the string if the (/ Min /max/.test (method) & amp; amp; (type === faucet || / numberregulation / test (type))) {value = number (value); } If (value) {rule [method] = value; } And if (type === method and & amp; type! == 'category') {// Exception: jquery does not test for valid 'category' method // html5 'category' type rules [method] = true ; }

As soon as I made a sluggish update for jqueryvalidation-1.11.1, fixed this problem, welcome to JS Package Hell!

No comments:

Post a Comment