dataannotations

Unique constriaint with data annotation

Hi, I'm using the System.ComponentModel.DataAnnotations namespace to validate my domain classes. How can I create a custom attribute to validate the uniqueness of a property regardless of the database(through some interface for example)? ...

ASP MVC 2 Data Annotations not working with VS2008/ASP 3.5?

I have added data annotations to a 'buddy' class as referenced in MS guidance. In particular, the [DisplayName ("Name")] does not seem to be affecting anything. My understanding is that the value assigned to the annotation should be referenced and used by the Html.LabelFor(m => m.Attribute) helper to display the label for the field. Am...

How to create Custom Data Annotation Validators

Wanting to create custom data annotation validation. Are there any useful guides / samples on how to create them? Firstly: StringLength with minimum and maximum length. I'm aware .NET 4 can do this, but want to do the same in .NET 3.5, if possible being able to define minimum length only (at least x chars), maximum length only (up to x ...

ASP.Net MVC 2 - jQuery Validation and Form Submit - DataAnnotations

I have a sample application, trying to learn jQuery validation and submit form in this scenerio. The page has one text box (EnvelopeID per class Envelope). If submit button is clicked and the text box is empty then i want to show an error message. If it is not empty then i want to post ajax request to GetData Action. The action returns...

asp.net mvc int property bind exception

I have a int property in my class and want to validate if the user has entered a string. How can I do that using data annotations? When I pass a non-integer value I get a excpetion like this: The value 'asdasd' is not valid for property. Any Ideas? ...

Will the ValidationResult.MemberNames property ever contain more than one value?

I search with reflector and I didn't manage to find a case where the ValidationResult.MemberNames is supposed to contain more than one value. So, first of all I am wondering why MS had to do it IEnumerable<string>, then now that they already did this, can I rely that this property will only return one value? Update Conserning the DataA...

NerdDinner form validation DataAnnotations ERROR in MVC2 when a form field is left blank.

Platform: Windows 7 Ultimate IDE: Visual Studio 2010 Ultimate Web Environment: ASP.NET MVC 2 Database: SQL Server 2008 R2 Express Data Access: Entity Framework 4 Form Validation: DataAnnotations Sample App: NerdDinner from Wrox Pro ASP.NET MVC 2 Book: Wrox Professional MVC 2 Problem with Chapter 1 - Section: "Integrating Validation and B...

Custom validation that checks if email already exists in DB. HELP!

Hi, I'm new to .net MVC but am making heads way. I'm trying to make a custom DataAnnotation validator that checks to see if an email address is already registered. I am using LINQ to SQL. My Model is below: // Model public class UsersRepository { private DigitalentDataContext db = new DigitalentDataContext(); BaseController base...

Asp.net Mvc2 Data Annotations Validation (Client Side works, Server side Doesnt??)

I'm using an entity model with metadata annotations. My controller method looks like this... if (!ModelState.IsValid) { return View(model); } else { UpdateModel(model); repo.Save(); return RedirectToAction("Index"); } If I enable client si...

Range DataAnnotation Doesn't Seem to Be Working in .Net 3.5

Using .Net 3.5 I have a Range Attributes (System.ComponentModel.DataAnnotations) on a Property... [Range(0, 5, ErrorMessage = "Weight must be between 0 and 5")] public virtual double Weight{ get; set; } And I have a Validate method in the class that checks validation attributes... protected virtual void Validate() { var t...

Attribute 'DisplayColumn' is not valid on this declaration type. It is only valid on 'class' declarations.

Just wondering why I get compile time error : "Attribute 'DisplayColumn' is not valid on this declaration type. It is only valid on 'class' declarations." using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.ComponentModel.DataAnnotations; namespace MyApplication.Models.DataAnnotations { ...

How can I access the DisplayName data annotation value from code?

public static string ProductHelper(this Product p) { // Need to get the DisplayName value for p.Name property } EDIT: [MetadataType(typeof(ProductMetadata))] public partial class Product { public class ProductMetadata { [DisplayName("Product name")] public object Name { get; set; } } } ...

Adding and Removing Data Annotations from code

Is there away to add and remove DataAnnotations, in particular the [requried], from the code side of things? My problem is that I want to give the user the ability to save an incomplete form in our crud applications but at the same time use the power of the DataAnnotations validation. If this is not possible, what is the best way I can...

Data Annotations Silverlight

Hi, I have a webservice that supplies data (Publisher Object) to a silverlight project. I want to bind the Publisher to a dataform and have the dataform handle to validation. I would like to achive this by using DataAnnotations. My question is.. Can I or how do you amend the Publisher object (Generated by the webservice) to add the D...

C# DataAnnotations and resource files - why no simple constructor?

I'm using DataAnnotions in a ASP.NET MVC application for validate my input models. If I want to use resource files for the error messages, then I have to specify these with named parameters, like so: [Required( ErrorMessageResourceType = typeof(Validation), ErrorMessageResourceName = "NameRequired")] Since I use this in a bunc...

how to put DisplayName on ErrorMessage format

Hello there, I have something like this: [DisplayName("First Name")] [Required(ErrorMessage="{0} is required.")] [StringLength(50, MinimumLength = 10, ErrorMessage="{0}'s length should be between {2} and {1}.")] public string Name { get; set; } I want to have the following output: First Name is required. First Na...

MVC Validation and business layer

The DataAnnotations validation happens in the default model binder and most of the examples I've seen uses the Model.IsValid in the Controller to verify if a model is valid or not. Since my controller action calls a business layer method and I like to validate the entity there: Do I have to explicitly switch off the model binder valida...

DataAnnotations or Application Validation block

Whats the difference between DataAnnotations and Application Validation Block? ...

Custom Validator Attribute exception in DataAnnotations

Has anyone seen this exception before? Google or Bing has absolutely very few results. IsValid(object value) has not been implemented by this class. The preferred entry point is GetValidationResult() and classes should override IsValid(object value, ValidationContext context). Here's the custom validator: public class PriceAttrib...

ASP.NET MVC 2 Data Validation: Does this carry from a DomainModel to a ViewModel?

Given my understanding of MVC and DDD (critique as necessary): Domain Models can be created by Factories, and persisted by Repositories. These are POCO objects. View Models contain partial or complete Domain Models as needed by the view. They are generated by a service that interacts with a repository. Thus Domain Models never make ...