how to disabble required attributes MVC model?

i have a model :
  [Range(1, 24, ErrorMessage = "Invalid Hour")]
    public int val1{ get; set; }
    [Required(AllowEmptyStrings = true)]
    public string val2 { get; set; }

Open in new window

i have a edit action also i have view page. There are 2 textboxes val1.text, val2.text if i write fill view form (i am not writing any value on val1) return InvalidHour. i want to give ability to set empty value (not writing something on val1). How to do it?
programmeristAsked:
Who is Participating?
 
ambienceCommented:
Something like this?

[Required(false)]
[Range(1, 24, ErrorMessage = "Invalid Hour")]
public int? val1{ get; set; }
0
 
programmeristAuthor Commented:
are you living? dont write any thing !!!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.