dataannotations

Compare Dates DataAnnotations Validation asp.net mvc

Lets say I have a StartDate and an EndDate and I wnt to check if the EndDate is not more then 3 months apart from the Start Date public class DateCompare : ValidationAttribute { public String StartDate { get; set; } public String EndDate { get; set; } //Constructor to take in the property names that are supposed to be che...

ASP.NET MVC2 Model Validation Fails with Non-US Date Format

I have a small MVC2 app that displays in two cultures: en-US and es-MX. One portion contains a user input for a date that is pre-populated with the current date in the Model. When using en-US, the date field is displayed as MM/dd/yyyy and can be changed using the same format without causing any validation errors. When using es-MX, the...

ASP.NET MVC 1.0 Model Binding + RadioButton Helper + Data Annotation

I'm having an annoying issue with the RadioButton helper and Data Annotation used for validation: I'm actually replacing a dropdown list with radio buttons (because the list is small). I'm not using MVC 2 or MVC Futures (though, I think I'd run into the same problem if I were using the RadioButtonList). That particular field is require...

dataannotation metadatatype register dll in global.aspx (linq to sql)

I am trying to use dataannotation validation(I am not able to Fire the annotations as yet) in my mvc application. with reference to this article I want to confirm http://www.asp.net/mvc/tutorials/validation-with-the-data-annotation-validators-cs I am using vs 2008 professional edition . Do I really need to download Microsoft.web.mvc.da...

mvc DataAnnotations how to make field no editable in 3.5

I have a few field in my entity that i wish to be non-editable. Looking in the docs it seems like "EditableAttribute" would do the trick. However this is only 4.0 Just wondering if there are other attributes that would have the desire effect. So be clear, i have a field called "DateRegistered" i wish to display this as string not text...

Common DataAnnotations in ASP.Net MVC2

Howdy, I have what should be a simple question. I have a set of validations that use System.CompontentModel.DataAnnotations . I have some validations that are specific to certain view models, so I'm comfortable with having the validation code in the same file as my models (as in the default AccountModels.cs file that ships with MVC2). ...

DataAnnotations multiple property validation in MVC

I am struggling with DataAnnotations in MVC. I would like to validate a specific property, not the entire class but need to pass in another property value to validate against. I can't figure out how to pass the other property's value, ScheduleFlag, to the SignUpType Validation Attribute. public class Event { public bool Sc...

Range annotation between nothing and 100?

Hi I have a [Range] annotation that looks like this: [Range(0, 100)] public int AvailabilityGoal { get; set; } My webpage looks like this: <%=Html.TextBoxFor(u => u.Group.AvailabilityGoal)%> It works as it should, I can only enter values between 0 and 100 but I also want the input box to be optional, the user shouldn't get an vali...

DataAnnotation attributes buddy class strangeness - ASP.NET MVC

Given this POCO class that was automatically generated by an EntityFramework T4 template (has not and can not be manually edited in any way): public partial class Customer { [Required] [StringLength(20, ErrorMessage = "Customer Number - Please enter no more than 20 characters.")] [DisplayName("Customer Number")] public v...

DataAnnotations - Disallow Numbers, or only allow given strings

Is it possible to use ASP.NET MVC 2's DataAnnotations to only allow characters (no number), or even provide a whitelist of allowed strings? Example? ...

ASP.NET MVC 2: Data DataAnnotations validation be convention

I have a required attribute that used with resources: public class ArticleInput : InputBase { [Required(ErrorMessageResourceType = typeof(ArticleResources), ErrorMessageResourceName = "Body_Validation_Required")] public string Body { get; set; } } I want to specify the resources be convention, like this: public class ArticleI...

MVC Validation in Model

I'm currently using DataAnnotations to validate my MVC 2 app. However, I've ran into a small problem. I currently have an object of type User which has a number of properties. All of which are required. public class User { [Required(ErrorMessage = "Username is required")] public string Username { get; set; } ...

DataAnnotations validation and custom model binder

I have an action method that accepts the following model - LanguagesViewModel: public class LanguagesViewModel : ViewModelBase { IEnumerable<LanguageItem> Languages { get; set; } } public class LanguageItem { [Required] public int LanguageId { get; set; } [Required] public int SpeakingSkillId { get; set; } [Required] public in...

.net Regular Expression to match any kind of letter from any language

Which regular expression can I use to match (allow) any kind of letter from any language I need to match any letter including any diacritics (e.g. á, ü, ñ, etc.) and exlude any kind of symbol (math symbols, currency signs, dingbats, box-drawing characters, etc.) and punctuation characters. I'm using asp.net MVC 2 with .net 4. I've trie...

MVC2 Client validation with Annotations in View with RenderAction

I'm having problem with client side validation on a View that renders a dropdownlist with help of a Html.RenderAction. I have two controllers. SpecieController and CatchController and I've created ViewModels for my views. I want to keep it as DRY as possible and I will most probably need a DropDownList for all Specie elsewhere in the n...

ModelMetadata: ShowForEdit property not appearing to work.

Iv wrote an MetaDataProvider like the one below and am using it in conjunction with Editor templates. The DisplayName is working correctly, but for some reason the ShowForEdit value it not having any effect. Any ideas? public class MyModelMetadataProvider : DataAnnotationsModelMetadataProvider { protected override ModelMetadata ...

DataAnnotations Automatic Handling of int is Causing a Roadblock

Summary: DataAnnotation's automatic handling of an "int?" is making me rethink using them at all. Maybe I'm missing something and an easy fix but I can't get DataAnnotations to cooperate. I have a public property with my own custom validation attribute: [MustBeNumeric(ErrorMessage = "Must be a number")] public int? Weight { get; set; }...

Validating method arguments with Data Annotation attributes

The "Silverlight Business Application" template bundled with VS2010 / Silverlight 4 uses DataAnnotations on method arguments in its domain service class, which are invoked automagically: public CreateUserStatus CreateUser(RegistrationData user, [Required(ErrorMessageResourceName = "ValidationErrorRequiredField", ErrorMes...

Using DataAnnotations 4.0

I am using DA 4.0 with a MVC application and have created a custom validator as shown below: public static ValidationResult NumberOfItems(int numItems, ValidationContext pValidationContext) { if (numItems == 1) { //Tag as critical error //return new ValidationResult... } ...

Define markup for [Required] fields in View in ASP.NET MVC 2.0

Hi, We have a model with properties decorated with [Required] which works great for validation. However, what we'd like to do is mark those required fields in the view with an asterisk (or some other style) to denote they are required before the user enters any data for validation. I don't seem to be able to find anything built into t...