dataannotations

How to specify order of Data Annotation errors in Html.ValidationSummary

I'm displaying errors on my form with the use of <%= Html.ValidationSummary("Please review the errors below") %> My domain object inherits from a base class and I am finding that the base class data annotation properties are being displayed at the bottom of the list. This goes against the order in which they appear in my form. Is the...

Data Annotations on object model shared between 2 apps

I have a class library that contains my object model. I'd like each object to have data annotations to place validation rules into my model so that validation can be shared across 2 apps. One is an MVC 2 app and the other is a Windows forms app. I need to be able to validate the object model manually from code using the data annotatio...

Silverlight Validation Not Working with Data Annotations

I have a form: <StackPanel x:Name="LayoutRoot"> <sdk:ValidationSummary /> <sdk:Label Target="{Binding ElementName=Greeting}" /> <TextBox x:Name="Greeting" Text="{Binding Greeting, Mode=TwoWay, ValidatesOnExceptions=True, NotifyOnValidationError=True}" /> <sdk:Label Target="{Binding ElementName=Name}" /> <Te...

Custom date format problem in MVC application.

I have the following model and view, and I would very much like to accept date values in the format 'dd/MM/yyyy'. However, despite using the DisplayFormat annotation, I still get a validation error using my chosen format. [MetadataType(typeof(MilestoneMetadata))] public partial class Milestone { public class MilestoneMetadata {...

Data annotations modelbinder in new mvc

Hi we are trying to upgrade our project to work in the latest version of VS 2010 and i have encountered a problem with the old Data Annotations Modelbinder. Dim modelBinder = New DataAnnotationsModelBinder() modelBinder.InvalidValueFormatter = _ Function(propDescriptor As PropertyDescriptor, value As String, displayName As String) _ ...

How can I reuse Model Metadata for custom View Models?

Hi, I'm working on an ASP.NET MVC 2 project with some business entities that have metadata dataannotations attributes applied to them (Validation attributes, Display attributes, etc.). Something like: //User entity public class User { [DisplayName("Vorname")] [Required(ErrorMessage = "Vorname fehlt")] ...

Applying Required Attribute Valiation on a Collection, IEnumberable

Hi, how can I apply Required Attribute like validation to the following without knowing how many elements will be in each collection: public class MyViewPageViewModel { [Required] public List<int> IntCollection { get; set; } [Required] public Dictionary<int, string> IntAndStringAllValueCollection { get; set; } [Required("Val...

Dependency injection into a Class annotation

Hi I'm trying to work out how to do the following: [CustomAnnotation(thisVariableShouldBeInjected)] public class MyClass { // Normal class stuff } Now the data annotation is decorating a WCF service class, which itself has constructor injection going on. Ideally I'd like to inject the annotation with a value using the Ninject IOC...

Custom DataTypeAttribute not triggering validation correctly

Related to this question I have created my own DateValidationAttibute to make sure a string is in a valid date format (e.g., MM/DD/YYYY) [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false)] public class DateValidationAttribute : DataTypeAttribute { public DateValidationAttribute() : base(DataT...

Serializing DataAnnotations

I would like to store DataAnnotations inside a database. How can I retrieve a string representation of a DataAnnotation by reflection (or by other means)? Example public class Product { [DisplayName("Price")] [Required] [RegularExpression(@"^\$?\d+(\.(\d{2}))?$")] public decimal UnitPrice { get; set;...