DataAnnotations dynamically attaching attributes
Apparently it is possible to dynamically attach DataAnnotation attributes to object properties at runtime and as such achieve dynamic validation. Can someone provide code sample on this? ...
Apparently it is possible to dynamically attach DataAnnotation attributes to object properties at runtime and as such achieve dynamic validation. Can someone provide code sample on this? ...
I have written a custom model binder for List in my MVC project however I am now stuck in how to get this binder to validate against my DataAnnotations validation attributes. I have found some posts on the interwebs that talk about similar scenarios, but I haven't been able to find anything that works for my particular scenario. Model...
I'll be tackling writing a custom date validation class tomorrow for a meeting app i'm working on at work that will validate if a given start or end date is A) less than the current date, or B) the start date is greater than the end date of the meeting (or vice versa). I think this is probably a fairly common requirement. Can anyone poi...
I've been reading up on Data Annotations (i.e. Scott Guthrie's blog post) and I am thrilled about the concept of having validation logic in one place. Has anyone been able to use this technique successfully when prompting the user to enter a subset of the properties associated with a given class? For example (pseudocode)... public c...
Hi My goal is simply to show a language-specific errormessage for a Required-Annotation: [Required(ErrorMessageResourceName = "LastNameRequired", ErrorMessageResourceType = typeof(ValidationMessage))] LastNameRequired is the key of the string in the resourcefile, ValidationMessage is the type generated by the resource file. The resou...
I am getting a strange issue with DataAnnotations in ASP.NET MVC 2which I am unable to get the hand of. I am trying to validate a DateTime In a Model Class I have defined private DateTime _dateFrom; [Required(ErrorMessage="Date is required")] public DateTime DateFrom { get { return _dateFrom; } set { _dateFrom = value; } } On...
To keep my model validation clean I would like to implement my own validation attributes, like PhoneNumberAttribute and EmailAttribute. Some of these can favorably be be implemented as simple classes that inherit from RegularExpressionAttribute. However, I noticed that doing this breaks client side validation of these attributes. I am a...
I would like use data annotations to handle validation in my Silverlight app. The built-in validation attributes (primarily StringLength and Required) are great, and make life very easy. However, they seem to have one critical flaw. If my locale is set to fr-CA, for example, the validation exceptions are still in English - 'The Name fiel...
I followed scottgu's blog here and tried to do data validation. Succeeded. However what I see is that if my field is a required field, i get an error as soon as i loose focus from my textbox. I want validation to happen only when I click submit. ...
Hi, there are several tutorials that explain how to use EF data annotation for forms validation using the MVC framework. And to use jquery for the client side. See e.g.: http://dotnetaddict.dotnetdevelopersjournal.com/clientvalidation_mvc2.htm I would like to achieve the same, but without using MVC/MVC2. I want to build a classic asp...
As well as DisplayName eg. [DisplayName("Address line 1 ")] public string Address1{get; set;} Html.LabelFor(model => model.Address1) I have a requirement to show tooltips eg. [DisplayName("Address line 1 ")] [ToolTip("The first line of your address as it appears on you bank statement")] public string Address1{get; set;} Html.Label...
I have a silverlight datagrid. Validation works very well using DataAnnotations. However if I add a new row to the grid I don't get validation kicking in until I actuall try and edit cells. Is there no way to force the grid to validate when a cell has not been clicked on? ...
I have this property on a class: public virtual decimal? Number { get; set; } When I'm using it on a form, MVC validates it automatically. If the user enters a letter, naturally an error is returned: "The value 'D' is not valid for Number." How do I change such error message or even control that behavior? I'm not finding the related...
As explained in http://erichauser.net/tag/validator/, ValidateSelf enables you to express validations in code. I know writing a custom attribute is not difficult, but why go into all that trouble just for one off validations. I can't help the feeling that validation by attributes is that much simpler than old method of writing a long...
Hi, I'm using MVC 2 and EF4. If have a view that displays my Application (class) properties. Not all the properties are displayed in the view. There are a couple of the properties that need to be set once the submit button is clicked. I'm getting client validation to pass, but my server validation is still failing. I receive an App...
so according to Gu IValidatableObject.Validate() should get called when a controller validates it's model (i.e. before ModelState.IsValid) however simply making the model implement IValidatableObject doesn't seem to work, because Validate(..) doesn't get called. Anyone know if there is something else I have to wire up to get this to wor...
I need to validate some sets of fields in a form, and I've researched enough to figure out how to do it with a Class level DataAnnotation attribute, but I'm thinking that this has got to be a not uncommon situation, so I'm wondering if anybody knows where such an attribute has been published. I'm not coming up with anything meaningful b...
if I decorate the properties of my ViewModels with attributes like this: public class Vm { [Required] [StringLength(35)] public string Name {get;set;} } I am going to get english validation messages: "this field is required" "The field Name must be a string with a maximum length of 35" how could I translate them ? ...
I have been using mvc2 for a while now, and when i need to set the template i use the DataType Attribute [DataType("DropDown")] public int Field { get; set; } I see others using UiHint to achieve the same results [UiHint("DropDown")] public int Field { get; set; } What is the difference between using these two a...
I am using DataAnnotations for validation (including client side) I have a form with multiple fields. Basic validation for individual fields work fine. Now there are a couple of fields of which atleast one needs to have a value (if there are 3 fields then either 1st or 2nd or 3rd field should have a value). I have read quite a few pos...