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
3
votes
3 answers

Changing Default "input is not in a correct format" Validation Error in RIA Services

I'm trying to change the default error message in a Silverlight DataGrid when the input is in an incorrect format. For example, you type letters into a numerical field. As you tab away, it says "input is not in a correct format." I've seen how to…
vbullinger
  • 4,016
  • 3
  • 27
  • 32
3
votes
1 answer

UniqueNationalId.IsValid(Object value, ValidationContext validationContext)

I wrote a custom attribute: public class UniqueNationalId : ValidationAttribute { private readonly UserService _userService; public UniqueNationalId() { _userService = new UserService(); } protected override ValidationResult IsValid(object…
sara
  • 31
  • 3
3
votes
1 answer

What's the difference between DataType(DataType.PhoneNumber) & PhoneAttribute

What's the difference between using DataType Attribute and passing in a value of DataType.Phone and the Phone Attribute which inherits from DataType and automatically sets DataType.Phone? Is there any difference between these two classes? class…
KyleMit
  • 30,350
  • 66
  • 462
  • 664
3
votes
0 answers

Custom validationattribute error message ignored

I have the following custom ValidationAttribute that works the same way as the Required validation attribute, but I accept the name of a property that will have its value concatenated to the error message. However, the error message always comes as…
juliano.net
  • 7,982
  • 13
  • 70
  • 164
3
votes
0 answers

WebAPI calls a custom validation attribute twice on POST method call - normal?

My issue: A custom validation attribute is called twice and not once when calling a webapi post method (with EF) - I am not sure if this is normal and would like a definitive answer. It validates at the following points: Just before the breakpoint…
DanAbdn
  • 7,151
  • 7
  • 27
  • 38
3
votes
2 answers

MVC3 ValidationAttribute for DateTime? returning DateTime.Max in IsValid(...)

I'm trying to write a custom ValidationAttribute for a DateTime? However, when it hits IsValid(object value) the value is already DateTime.Max Nothing I can see in my code has set this value, but it means I am struggling to validate it. The rule I…
BlueChippy
  • 5,935
  • 16
  • 81
  • 131
3
votes
0 answers

Restrict the use of an attribute validation (ValidationAttribute ) for only one property type

the question is this: How I can I restrict my validation attribute to be used for only one type?, For example only DateTime. Currently I do this control method "IsValid": protected override ValidationResult IsValid(object value, ValidationContext…
andres descalzo
  • 14,887
  • 13
  • 64
  • 115
2
votes
1 answer

Get Custom Validation Attribute in MVC3 fire on Submit only and not when input loses focus

I am looking to get some custom validation attribute in MVC 3 to fire only when I submit and not when the input loses focus. Here is my custom validation attribute. #region Password Match Validation Attribute public sealed class PasswordPresent…
Nollaig
  • 1,097
  • 2
  • 12
  • 26
2
votes
0 answers

ASP .NET MVC 3 Validation unobtrusive - Evaluation order of the validation rules

I have created a custom ValidationAttribute "RequiredIf", to determinate wether a field is empty or not according to another field. I have created the adapter and I have added the method. Here is the example:…
2
votes
3 answers

How to programatically turn on/off a Data Annotation Validation Attribute

So, I am using ASP.NET MVC 3 and Entity Framework 4.1 (code-first). I have a class like this: public class Person { public int Id { get; set; } public string Name { get; set; } [Range(18, 99)] public int Age { get; set; } } The…
2
votes
2 answers

How to force ValidationAttribute to mark specified object members as invalid?

I've got my model which contains some members: public class Address { public Street { get; set;} public City { get; set; } public PostalCode { get; set; } } Now I've got my ValidationAttribute with IsValid method overrided like…
Łukasz W.
  • 9,538
  • 5
  • 38
  • 63
2
votes
1 answer

How to create custom validation attribute for Iranian national code in asp.net core?

I'm trying to validate the national code in asp.net core. I found the validation code and it works when I use it as a method but I want to create it as an validation attribute.This is my code in attribute class: public class…
niki tmb
  • 177
  • 1
  • 14
2
votes
1 answer

C# Razor page required attribute on IFormFile works only when clicking away

The goal here is to get input="file" Required validation attribute to work before clicking away. Now when I select file to upload I have to click away for require validation to work. In result I have to double click submit. index.cshtml.cs …
2
votes
1 answer

How to implement validation rules for elements from a partial view

We are developing a .net core 3.1 MVC application (actual with MVVMC). We have implemented custom validation attributes. And want them to be checked on server and on client side. The view is a standard view, however the user has the possibility to…
2
votes
1 answer

Pass Property of Class to ValidationAttribute

I am trying to write my own ValidationAttribute for which I want to pass the value of a parameter of my class to the ValidationAttribute. Very simple, if the boolean property is true, the property with the ValidationAttribute on top should not be…
Tom el Safadi
  • 6,164
  • 5
  • 49
  • 102
1 2
3
11 12