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
1
vote
0 answers

Using 'ErrorMessageResourceType' without static properties

I am stepping into the world of validation attributes in an attempt to subscribe more strongly to DRY. I do not use the in-the-box resource system because by experience it is buggy as hell. So I've developed an XML based resource provider that is so…
Jordan
  • 9,642
  • 10
  • 71
  • 141
1
vote
1 answer

ASP.NET MVC 3 IClientValidatable Attribute - Clear Parameters Cache

I'm using ASP.NET MVC 3. I have my added my own custom validation attribute: public class CustomAttribute : ValidationAttribute, IClientValidatable { private readonly string _parameter1; public CustomAttribute(string parameter1) { …
nfplee
  • 7,643
  • 12
  • 63
  • 124
1
vote
2 answers

Asp.Net MVC 3.0 Model Localization With RegularExpression Attribute

I've written a custom error message localization logic in my custom DataAnnotationsModelMetadataProvider class. It's working just fine with build-in StringLengthAttribute or RequiredAttribute validation error messages. But i am having trouble with…
1
vote
1 answer

How do I create conditional ValidationAttribute error messages?

I have a custom ValidationAttribute in my ASP.NET MVC3 project which has two conditions which need to be met. It works well but I would like to let the user now which validation rule has been broken by returning a customised error message. With the…
Dhaust
  • 5,470
  • 9
  • 54
  • 80
1
vote
2 answers

Create a custom date range validator that accepts dynamic values

The existing .Net range attribute validator only accepts static string values. I would like to create a validator that accepts dynamic values. For example I would like the age range to be 16 years to 200. If I input the minimum birthday as…
John the Ripper
  • 2,389
  • 4
  • 35
  • 61
1
vote
0 answers

mvc3 unobtrusive validation - yield return new ModelClientValidationRule with ValidationType value

I'm trying to work out how to create a MinValue attribute that contains the necessary Client validation rules to work client side - I have this which is based on other attributes I have created but I'm not sure how to add the _minValue to the…
Rob
  • 10,004
  • 5
  • 61
  • 91
1
vote
2 answers

Get full name of Complex Type from ModelClientValidationRequiredIfRule method in custom ValidationAttribute

I am using the example at The Complete Guide To Validation In ASP.NET MVC 3 to create a RequiredIf validation attribute (it's about 1/3 down the page under the heading of "A more complex custom validator"). It all works fine with the exception of…
bigmac
  • 2,553
  • 6
  • 38
  • 61
1
vote
1 answer

MVC3 simple custom validation

simple custom validation, my model and custom validation: public class Registration { [Required(ErrorMessage = "Date of Birth is required")] [AgeV(18,ErrorMessage="You are not old enough to register")] public DateTime…
Benk
  • 1,284
  • 6
  • 33
  • 64
0
votes
2 answers

Custom ValidationAttribute on two properties

I am trying to validate two fields in a class that must total less than a third value. If Property1 + Property2 is greater than X then show an error. I've created a custom attribute that will throw the error on the changed field if the total is…
Jay
  • 878
  • 3
  • 12
  • 22
0
votes
1 answer

Is it possible to customize a jquery validation message during the validation function using MVC unobtrusive adapters?

I have a multiple select listbox in an MVC3 form. A user can add & remove custom option elements to and from this listbox. However I want to validate that no 2 options in the listbox contain the same value. I have created a custom…
0
votes
1 answer

Why is "memberNames" parameter in "ValidationResult" is a collection type?

I understand, this is how we develop our custom validation attribute in ASP.NET: [AttributeUsage(AttributeTargets.Property | AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] public class…
phougatv
  • 881
  • 2
  • 12
  • 29
0
votes
0 answers

GetService(typeof(IConfiguration)) method in Validation attribute returns null object

I am trying to get a service of type IConfiguration in my validation attribute class, it gives null object but strangely if I out a debug point on the next line after creating the service object it gives the object instead of null. I am not sure…
0
votes
1 answer

Is dbContext (retrieved from ValidationContext.GetService in Blazor Server Side app) thread safe?

Is dbContext (retrieved from ValidationContext.GetService in Blazor Server Side app) thread safe? public class SomeAttribute : ValidationAttribute { protected override ValidationResult IsValid(object value, ValidationContext validationContext)…
0
votes
1 answer

.NET Core - How to solve email aready exist when updating data with the same email

I am trying to make an API using MongoDB and .NET Core. But I face a problem while updating the value. I wrote a custom validation like this: public class EmailUserUniqueAttribute : ValidationAttribute { protected override ValidationResult…
0
votes
2 answers

Client side custom validaton with attribute doesn't work

I have created custom validation attribute [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = true)] public sealed class ValidateDublicateNameAttribute : ValidationAttribute,…
Artur Keyan
  • 7,643
  • 12
  • 52
  • 65