Creating Custom Annotations Validation Attribute Using ASP.NET MVC Framework

preview_player
Показать описание
In this screencast Mohammad Azam will demonstrate how to create custom data annotation validation attribute using ASP.NET MVC Framework.
Рекомендации по теме
Комментарии
Автор

@HookaMega In my example I passed a constant number for the age. You cannot pass a value of one property to the attribute decorated on a different property. Check out the IValidableObject interface which is new in ASP.NET MVC 3 framework. I am working on some ASP.NET MVC 3 videos which will be available soon!

azamsharp
Автор

@HookaMega

If you have to have a property which is dependent on some other property then I would suggest you check out the IValidatibleObject interface.

azamsharp
Автор

@HookaMega Yeah I think I was using some old microphone at that time. New videos will have good sound quality. Thanks for watching!

azamsharp
Автор

@azamsharp
I did some research & IValidableObject is a very nice feature and gives me a lot more flexibility. But I also discovered that with MVC 3 we now have the validationContext available within custom attributes, which provides us with more information about the class. PluralSight has a video regarding this and in his demo he shows the ability to pass in the other property for comparison.

HookaMega
Автор

@azamsharp
even if the two properties are in the same class? Can't I just pass the current value of one property into the custom validation attribute? sort of like you did in your example, you specified the max age int when you decorated the model property..

HookaMega
Автор

This was a big help but i am having trouble figuring out how to make a property required based on the value of another property. Also what if you need to pass more than one value into your custom attribute?

thanks

HookaMega
Автор

@azamsharp
Thank you sir, keep up the good work.... Oh and by the way, the audio in your videos is too low. Even when I encrease my PC volume your video sound is too low. Thanks

HookaMega
Автор

great video, this is server side validation, is it hard to do similar but make it a client side validation? or maybe you have a video already for it.. plz let me know.

skolker
Автор

What is the difference between this kind of validations and the others ones?

Makku