0

Asp.net mvc2: How to add validation rules - A number field is not required but has range limitation?

3
  • This question is pretty thin; if you add more detail, showing perhaps what you have and what is not working, it will be easier to answer. Commented May 28, 2010 at 23:11
  • 1
    How can a number be optional but still have a restricted range? I'm pretty sure null is not between 1 and 10. Commented May 28, 2010 at 23:25
  • Using the Required attribute will not allow 0 whereas a Range attribute from 0 to 255 will. Commented May 28, 2010 at 23:28

1 Answer 1

1

Use the Range Attribute from DataAnnotations.

[Range(0, 255, ErrorMessage="The number must be between 0 and 255.")]
Sign up to request clarification or add additional context in comments.

Comments

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.