MVC 4 Beta project fails to compile after upgrading to .Net 4.5.
This happens due to conflict between System.ComponentModel.DataAnnotations.CompareAttribute
and System.Web.Mvc.CompareAttribute
System.ComponentModel.DataAnnotations.CompareAttribute
MSDN documentation says:
Provides an attribute that compares two properties.
While System.Web.Mvc.CompareAttribute
MSDN documentation says:
Provides an attribute that compares two properties of a model.
What is the difference between the two and when it would be "smarter" to use each of them?
10x.
So, looking at the MSDN documentation and doing a literal comparison of the two classes, I noticed both classes are derived from System.ComponentModel.DataAnnotations.ValidationAttribute. In fact, the classes are almost exactly the same. The only notable difference is that the MVC version also implements IClientValidatable which adds the following properties:
As for which class you should use, if the model will be directly bound to a view, use the MVC version so that you can take advantage of the client-side validation. However, if you're using ViewModels, you can stick with the ComponentModel class and avoid the unnecessary overhead of the additional properties. Your call!
System.Web.Mvc.CompareAttribute
System.ComponentModel.DataAnnotations.CompareAttribute
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With