Questions tagged [validationattribute]

Used for classes Validation Attribute Classes in .NET within the System.ComponentModel.DataAnnotations namespace

The ValidationAttribute class provides validation on class properties. It can be overridden to provide custom validation logic.

When implemented with IClientValidatable and also adds client side validation logic.

The following classes are derived from Validation Attribute:

180 questions
0
votes
1 answer

Custom validation attribute does not work when editing a record

I have an entity called Doctor, in the create doctor form I added custom validation logic as follows: public class UniqueDoctorNameAttribute : ValidationAttribute { protected override ValidationResult IsValid(object value, ValidationContext…
0
votes
1 answer

ASP.Net MVC:Bit different kind of conditional validation server side and client side

i am in a situation where i have to achieve bit wired conditional validation server side and client side. the story as follows a) suppose i have one dropdown b) two checkboxes, c) one radio button list d) one checkbox list e) few textbox and f) save…
Mou
  • 15,673
  • 43
  • 156
  • 275
0
votes
1 answer

check different ValidationAttributes and make a logical decision?

I want to achieve the following, but it seems that its not possible: [genericValidation || specificValidation] public int content{ get; set; } I dont want to fuse both validations, because genericValidation is used in multiple places in the…
luisluix
  • 547
  • 5
  • 17
0
votes
2 answers

Custom validation attribute is not working on numeric properites

I have a custom validation attribute for validating decimal properties public sealed class DecimalAttribute : ValidationAttribute { public DecimalAttribute() { this.ErrorMessage = "The input must be a decimal number"; } …
user3530012
  • 720
  • 2
  • 20
  • 37
0
votes
1 answer

.Net MVC2 How to add error to ModelState when using custom ValidationAttribute

I have the following ValidationAttribute class [AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)] public sealed class DateValidationAttribute : ValidationAttribute { public DateValidationAttribute(string…
0
votes
1 answer

How To Disable or Change Attribute According to CRUD Operation Insert Or Update

I'm trying to build a small website using ASP.NET MVC With EntityFramework on Visual Studio 2013.4 I have this model: public Class User { Public int UserID {get;set;} [Required] [ValidUserName] public string UserName…
Loai
  • 732
  • 16
  • 32
0
votes
1 answer

How come module-level validators are evaluated only after property-level validators?

I'm using the module-level validator: 'PropertiesMustMatch' on my view-model, like so: [PropertiesMustMatch("Password", "PasswordConfirm")] public class HomeIndex { [Required] public string Name { get; set; } public string Password {…
Jonathan
  • 32,202
  • 38
  • 137
  • 208
0
votes
1 answer

My Validation attribute with client side

I have a business rule of my page - controls with date should be in ascending order. I.e. entered value to Date1 < entered value to Date2 < Date3 My attribute: public class CompareDateAttribute : ValidationAttribute, IClientValidatable { public…
Oleg Sh
  • 8,496
  • 17
  • 89
  • 159
0
votes
1 answer

Validationattribute only when value is changed?

I want to write a custom ValidationAttribute that checks if the given value is unique or not. The problem is that in the edit screen, it is not guaranteed that the user actually changed the value, resulting in a false error. Is there a way to…
Boris Callens
  • 90,659
  • 85
  • 207
  • 305
0
votes
1 answer

Create a DataTypeAttribute that uses an Editor Template and is a ValidationAttribute

Using MVC5 and .NET 4.5 I want to make a DataTypeAttribute that will both use a Editor Template and work as a ValidationAttribute. As I understand it, DataTypeAttribute inherits from ValidationAttribute so I didn't think this would be…
0
votes
1 answer

C# Custom Attribute Required If

I am just getting into custom attributes, and I absolutely love them. I am wondering if it is possible to create an attribute that gets applied to a property and denotes the name of another property in the same object. If would check to see if the…
Jim Shaffer
  • 101
  • 1
  • 2
  • 14
0
votes
3 answers

Custom ValidationAttribute test against whole model

I know this is probably not possible but let's say I have a model with two properties. I write a ValidationAttribute for one of the properties. Can that VA look at the other property and make a decision? So; public class QuickQuote { public…
griegs
  • 22,624
  • 33
  • 128
  • 205
0
votes
2 answers

How to pass view model data through to ValidationAttribute?

So I have a simple custom validation attribute: public class MyCustomValidator : CustomValidationAttribute { public bool IsLive { get; set; } public MyCustomValidator() { //Service locator stuff } protected override…
Ben
  • 187
  • 3
  • 12
0
votes
1 answer

Custom Attribute client side Validation inside Collection

I'm using this custom validation. public class DynamicRangeValidator : ValidationAttribute, IClientValidatable { private readonly string _minPropertyName; private readonly string _maxPropertyName; public DynamicRangeValidator(string…
0
votes
0 answers

Create custom ValidationAttribute

I am trying to make my own ValidationAttribute but when I need the "value" it is null. I have my ViewModel like this public class PacienteVerificarVM : IIdentifiableObject { [DniFormatoCorrecto] public string NumeroDocumento { get; set;…
Claudio Gareca
  • 109
  • 1
  • 11
1 2 3
11
12