Solved

how to disabble required attributes MVC model?

Posted on 2012-04-13
2
261 Views
Last Modified: 2012-05-07
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?
0
Comment
Question by:programmerist
2 Comments
 

Author Comment

by:programmerist
ID: 37842605
are you living? dont write any thing !!!!
0
 
LVL 22

Accepted Solution

by:
ambience earned 500 total points
ID: 37845378
Something like this?

[Required(false)]
[Range(1, 24, ErrorMessage = "Invalid Hour")]
public int? val1{ get; set; }
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question