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
7
votes
1 answer

Custom ValidationAttribute doesn't work

I tried to create a custom ValidationAttribute: public class RollType : ValidationAttribute { public override bool IsValid(object value) { return false; // just for trying... } } Then I created (in another class) - …
TamarG
  • 3,522
  • 12
  • 44
  • 74
6
votes
2 answers

How to serialize a model with all validation attributes from the individual properties?

Context: creating a jsonP service with mvc controller methods which provides a definition of formfields including all validation rules. My problem is that I do not know how to serialize the validation attributes. I prefer the validation attributes…
5
votes
5 answers

How can I validate Guid datatype?

Is there a way to validate GUID datatype? I'm using validation attributes. http://msdn.microsoft.com/en-us/library/ee707335%28v=vs.91%29.aspx
Darf
  • 2,495
  • 5
  • 26
  • 37
5
votes
1 answer

ValidationErrors of custom ValidationAttribute not properly displayed

I have a ValidationAttribute that I have created which is shared between the Server, and Client. In order to get the validation attribute to properly generate to the client when referenced within a data helper class I had to be very specific in how…
5
votes
2 answers

How to localize standard error messages of validation attributes in ASP.NET Core

How to localize standard error messages of validation attributes in ASP.NET Core (v2.2)? For Example, [Required] attribute has this error message "The xxx field is required."; [EmailAddress] has "The xxx field is not a valid e-mail address.";…
5
votes
4 answers

Custom Model Validation based on two properties. One influence the other one

I Use Asp.Net MVC 2 with entity framework 4. Here is the situation : I Have a checkbox and a textbox(Date Picker). If the checkbox is checked, the textbox is required. If the checkbox is false, the textbox is not required. Checkbox True => Textbox…
5
votes
3 answers

ASP.NET Custom ErrorMessage for Model Enum field

I am developing a website built on EntityFrameworkCore and targeting ASP.NET Core 2.1. I want to specify an error message for an enum field in my model like so: [Required(ErrorMessage = "Select an item from the list.")] public MyEnum MyEnum { get;…
5
votes
2 answers

ASP.NET MVC Regex validation with Unicode is not supported on client side validation

I want to validate a given string that will be used to save the file with the required name in the server. this requires me to use the following REGEX:^[\p\w\-. ]+$ which works great but only for English strings. so I have modified it like this…
Mortalus
  • 10,574
  • 11
  • 67
  • 117
5
votes
1 answer

How to trigger validation on one property when another property has been validated, using custom ValidationAttribute and INotifyDataErrorInfo

Up until recently, I have used a custom extended version of the IDataErrorInfo interface. My extension enables me to work with multiple errors simultaneously and so far, it's served me very well. However, with the introduction of the…
Sheridan
  • 68,826
  • 24
  • 143
  • 183
5
votes
1 answer

GetClientValidationRules is never called in MVC application

I have a custom ValidationAttribute that implements IClientValidatable. But the GetClientValidationRules is never called to actually output the validation rules to the client side. There is nothing special about the attribute but for some reason it…
Kyro
  • 748
  • 1
  • 12
  • 28
4
votes
1 answer

I need to return customized validation result (response) in validation attributes in ASP.Net core Web API

I need to return customized validation result (response) invalidation attributes in ASP.Net core Web API This is the ValidationAttribute I have created. class MaxResultsAttribute : ValidationAttribute { protected override ValidationResult…
4
votes
1 answer

ASP.NET Core Custom Validation Attribute Not Firing

I have a GET method in API Controller. I would like that method to be validated using custom validation attribute as below. However it's not getting fired for some reasons. [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] public…
Alan B
  • 2,219
  • 4
  • 32
  • 62
4
votes
1 answer

Will the ValidationResult.MemberNames property ever contain more than one value?

I search with reflector and I didn't manage to find a case where the ValidationResult.MemberNames is supposed to contain more than one value. So, first of all I am wondering why MS had to do it IEnumerable, then now that they already did…
Shimmy Weitzhandler
  • 101,809
  • 122
  • 424
  • 632
4
votes
1 answer

Programmatically validate using data annotations?

I have a property of entity subclass, I'd like to validate if it's null. I can't annotate it with the [Required] attribute, because then the EF parser interprets it as required. I only want it to be required for this type (it's an inherited…
Shimmy Weitzhandler
  • 101,809
  • 122
  • 424
  • 632
4
votes
1 answer

Limitation of ModelState.IsValid in ASP.NET MVC 3

I always use ModelState.IsValid for check all of my model validation validated correctly in Server Side, but I think there is a limitation to use this. For example I define a Remote Validation attribute, but if I disable javascript then…
1
2
3
11 12