dataannotations

How to validate for different clients with DataAnnotations in .NET

If you write your validation requirements into the domain object using DataAnnotations how can you vary these depending on the UI that accesses it - for example the validation requirements of a user signup form may be different from the requirements of the administrators form - yet they both use the same domain object behind the scenes. ...

MVC 2 Client and Server Validation with Data Annotations - Required not working

I have a Create view which is passed a ViewModel. The ViewModel contains the following: namespace MyProject.ViewModels { public class MyObjectCreateView { public MyObject MyObject { get; set; } public List<OtherObject> OtherObjects { get; set; } } } The objects are generated using Entity Framework. I have...

How can I use the Data Validation Attributes in C# in a non-ASP.net context?

I'd like to use the data validation attributes in a library assembly, so that any consumer of the data can validate it without using a ModelBinder (in a console application, for instance). How can I do it? ...

User controls within table using MVC2 issues

I have a ascx file (with its own viewmodel) that displays a table. Each row in the table will have a user control (with their own ViewModel - created from the ascx viewmodel). The main problem is with validation. The individual user controls on each row use DataAnnotation validation with a Validation summary at the top of it, when runni...

"RequiredAsSet" validation attribute

I'm using the data annotations attributes for validation in my app, and I want to have a RequiredAsSet attribute, which will require either all properties decorated with the attribute to be populated, or none of them. The set cannot be part populated. I thought a clever way to do it would be like this: public class RequiredAsSetAttribu...

How best to handle late data validation using asp.net MVC 2's data annotation validation?

Typical scenario, post to an action that checks ModelState.IsValid and if it is, saves to the DB. Validation rules are set as data annotations in the Model. Here's my issue. I have a data field that can't be longer than 400 characters. The data annotations enforce this, as well as a jQuery validation on client side. User enters 395 cha...

When will Mono support System.ComponentModel.DataAnnotations??

I've been trying asp.net mvc on mono and the data annotation throws a not implemented exception, does anyone know when will Mono support this? According to this page http://www.go-mono.com/status/status.aspx?reference=4.0&amp;profile=4.0&amp;assembly=System.ComponentModel.DataAnnotations, it's almost finished... ...

MVC 2 custom data annotations on partial entity class property not registering validation error?

Hi All, I have a data entity class which I have added a property to using a partial class: [MetadataType(typeof(LocaleMetaData))] partial class Locale { public sealed class LocaleMetaData { [Required(AllowEmptyStrings = false, ErrorMessage = "A locale must have a descriptive ...

Validation on subclasses

Hello. I've a small inheritance-tree like this: BaseGuest -> GuestA -> GuestB -> GuestC BaseGuest has a member 'Firstname' which is required for GuestA and GuestB, but not GuestC. So I've there are Required-Annotations on GuestA.Firstname and GuestB.Firstname. [Required(ErrorMessageResourceName = "FirstNameRequired", ErrorMessag...

Silverlight 4, RIA Services & Data Annotations. Tooltips not appearing on DataForm.

I'm having a problem with data annotations and the automatic tool tips on my DataForm fields. The objects bound to the DataForm have been decorated with the Display and Description attributes e.g. [Display(Name = "Email Address:", Description="We do not sell your information!")] public string EmailAddress { get; set; } The expected to...

Is Data Annotations really a good idea for validation?

As I'm learning more and more about ASP.NET MVC the more I am introduced to Data Annotations. Specifically in MVC they are used for validation and this gives me some concerns. The biggest is due to the fact that I like to keep my model as POCOs and as clean as possible. Now what if I have those model classes shared across multiple projec...

Dynamically modifying DataAnnotation Attributes

I have a simple integer property in a display model. We'll call it "MaxDays". I'm building an MVC app, and I've got the standard set of display and validation statements which will make use of the DataAnnotation attributes attached to the model: <%: Html.LabelFor(x => x.MaxDays) %> <%: Html.TextboxFor(x => x.MaxDays) %> <%: Html.Valida...

Validation in ASP.NET MVC 2

Hi, I have some problems with validation using Data Annotations in ASP.NET MVC 2. For example, I have Address class: public class Address { public long Id { get; set; } [Required] public string City { get; set; } [Required] public string PostalCode { get; set; } [Required] public string Street { get; set;...

DataAnnotations MetadataType Class Ignores Base Class Properties

I've run into a bit of a wall in trying to use the .NET DataAnnotations feature to provide simple validations in a derived class. I am marking up my class with the standard annotations included in .NET 4 (from the System.ComponentModel.DataAnnotations namespace), then using the MS Enterprise Library v5 Validation Block to process the rul...

DataAnnotations and FluentValidation not working in MVC 2 project

I have edited the original question since the same error is occurring the difference being the implementation, I have now added Ninject to the mix. I have created a class for the validation rules public class AlbumValidator : AbstractValidator<Album> { public AlbumValidator() { RuleFor(a => a.Title).NotEmpty(); } } I ...

How to do Data Annotations on an object in another Assembly?

I have an abstract domain object that is consumed by both a web and windows application. This domain object sits in a an old namespace along with any derived classes. For my web application I would like to use data annotations. Usually I would create a partial class to the domain object and provide it a MetaData class. However, I am una...

Storing validationmessages in database

Hello I currently have a resource-file where I store "errormessages". And I would like to change it so it uses database. I have functions that returns from database. Whats needed to do more in my class besides the "retrieve-error"-part to use it like I did before: [Required(ErrorMessageResourceType = typeof(ErrorMessages), ErrorMessage...

Class-level validation

Hello! I am validating a class with DataAnnotations utils. I have a class that has a Title property and an Item property. I want to apply a RequiredAttribute to the Title property but it should be invalid only if the Item property is null; if the Item property is set with an object, the Title is not required. In short words, I want th...

Validating uniqueness with data annotations in asp.net mvc

Hi, I have various questions about validation using data annotations. I am using the following setup asp.net mvc 2 entity framework 4 data annotations Basically, I'm trying to get unique validation working and i'm a little confused. My models are as follows: public class Buyer { public int Id { get; set; } [Required(Erro...

Is there any way to get a MetaDataType generated from my WCF service

How do I get DataAnnotations from the WCF server to the Silverlight client, (note: not using RIA Services) ...