asp.net mvc - How i can use two optional object in c# when one of them is required? -


After

I have found information on the page through the query string and I validate them through the data annotation feature.

On the page I found PID or EID. In each of them, one of them is always one of them, how can I validate them in MVC.

Can anyone tell me that I can do this in C # asp.net MVC via data annotation.

Public String PID {Received;

Set {eId = value; PID = value; }} Public string EID {get; Set; }

If I understand you correctly, the situation is that you Allways Either a PID set or EID is needed - one of them can be empty / empty, but never both. And you want to do it with any type of data connection instead of any other kind of recognition.

I do not know if it is possible what is there but I doubt it. But you can apply your own (as Phil shows in the great blog post):

I want this because you want to validate your Id / PID in an Eid-class With the need to remove this work seems to be done for your annotated field.

There is another way to apply -Interface (see blog post)

Here is an example for your type

  Class MyClass : IValidatableObject {public string id {get; Set;} public string pid {find; Set;} Public IEnumerable & LT; ValidationResult & gt; ValidationContext VC {if (string.IsNullOrEmpty (Eid) & amp; String.IsNullOrEmpty (PID)) returns the new ValidationResult ("Eid or PID should be set up"; New [] {"Id", "pid"}); }}   

and lastly on MSDN:

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

ruby on rails - Convert a Activerecord result with has_one associations into a single hash per record -

javascript - Read complete data from stream from onMessage -