Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how to disabble required attributes MVC model?

Posted on 2012-04-13
2
Medium Priority
?
272 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Author Comment

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

Accepted Solution

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

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

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

722 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