2

Here is the class code check there is no DataAnnotation.

 public int Rotate { get; set; }

Here is the its use

@Html.HiddenFor(model => model.Screen.Rotate)

Here its generating html, y its generating validation rules????

<input type="hidden" value="" name="Screen.Rotate" id="Screen_Rotate" data-val-required="The Rotate field is required." data-val-number="The field Rotate must be a number." data-val="true">

Note: If i change int Rotate to string Rotate then it does not generate extra attributes for validations like data-val-required, data-val-number etc.

5
  • Have you tried using int? instead of int ? Commented Feb 7, 2011 at 16:56
  • Yes I have tried int? but still same html is generating Commented Feb 7, 2011 at 17:02
  • Are you sure? Yes, you'll get the number validation, but you should not be getting required with int? . Your problem may be elsewhere. Commented Feb 7, 2011 at 17:10
  • here is the code pastebin.com/0gpwTGKz Commented Feb 7, 2011 at 17:19
  • Take a look at this question: stackoverflow.com/questions/4700172/… Commented Feb 7, 2011 at 20:06

1 Answer 1

6

Non-nullable scalar values such as int and DateTime are always considered as required. string isn't required since strings are nullable. As @Biff said, use int? for a non-required int.

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

2 Comments

Please don't create a brand new question covering the same problem as an existing question with no accepted answer. Please update the existing question instead.
coure06- that completed question just points back to this one

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.