Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6474465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:35:24+00:00 2026-05-25T06:35:24+00:00

i got the information on page through query-string and i validate them through the

  • 0

i got the information on page through query-string and i validate them through the data annotation feature.

on the page i got the pId or eId. the one of them in every situation the one of them are always found how i can validate them in MVC.

can someone tell me how i can do this in c# asp.net mvc through the data-annotation.

are this works if i do it

 public string pId 
        {
            get;
            set
            {
                eId= value;
                pId = value;
            }
        }

        public string eId
        {
            get;
            set;
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T06:35:24+00:00Added an answer on May 25, 2026 at 6:35 am

    If I understand you correctly the situation is that you allways need either pId set OR eId – one of them might be null/empty but never both. And you want to do this with some kind of DataAnotation instead of some other kind of validation.

    I don’t know if this is possible directly with what is there but I doubt.
    But you can implement your own custom validation attribute (as Phil shows how in this great blog-post):

    I guess to work this with this you need to extract your EId/PId into a Id-class because the object to validate will be value of your annotated field.

    Another way would be to implement the IValidatableObject-Interface (see this blog post)

    Here is a example for your type

    class MyClass : IValidatableObject
    {
       public string EId {get;set;}
       public string PId {get;set;}
    
       public IEnumerable<ValidationResult> Validate(ValidationContext vC)
       {
          if (string.IsNullOrEmpty(EId) && string.IsNullOrEmpty(PId))
             yield return new ValidationResult("one of EId or PId must be set!", new []{ "EId", "PId" });
       }
    
    }
    

    And finaly here is a nice overview on MSDN:

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a problem with System.Windows.Forms.WebBrowser On every machine, with the exception of one,
In a SQL database I got storage information for each user, for each customer.
I'm trying to improve performance in our app. I've got performance information in the
I am working on an application which has got some sensitive information. I am
Anybody knows how to do this? I got all the information of the email
I've got a table of student information in MySQL that looks like this (simplified):
I've got an IR sensor which writes its current information to a token which
I've got a MySQL database that stores image information. Right now it only has
I've got a simple asmx web service that just needs to log some information
I've got a very large table (~100Million Records) in MySQL that contains information about

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.