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

How to fake ValidationContext using FakeItEasy?

I have one class which is derived from ValidationAttribute (of DataAnnotation in MVC) Following is the overridden method of this class: protected override ValidationResult IsValid(object value, ValidationContext validationContext) { …
Nirman
  • 6,715
  • 19
  • 72
  • 139
0
votes
2 answers

ValidationAttribute to verify the value is on the property a generic list

In our database we have several code tables that we use for referential integrity (ex emailTypes, phoneTypes, countryCodes, stateCodes). In our application we load and cache these tables into generic lists. Right now the application has custom…
0
votes
1 answer

MVC 4 Validation Attribute is not working for dynamically added fields

Here are my Product and ProductItem classes/models: public class Product { public int ProductId { get; set; } [Required(ErrorMessage="Enter Name")] public string Name { get; set; } public…
Ali Shahzad
  • 5,163
  • 7
  • 36
  • 64
0
votes
1 answer

Accessing ErrorMessage from within custom validation attribute

I want to be able to read the ErrorMessage string passed into a custom validation attribute so I can do some string.Format()ing on it. But I can't seem to find it? So for example I have a custom attribute: [IsDateBeforeFixedDate(4, 0, 0,…
Liam
  • 27,717
  • 28
  • 128
  • 190
0
votes
1 answer

Don't understand the mechanics of writing own validation attribute

I have written an attribute before, but I I have not written a validation attribute before. I am seriously confused about how it all works together. I have read most of the tutorials online about how to go about accomplishing this. But I am left…
SoftwareSavant
  • 9,467
  • 27
  • 121
  • 195
0
votes
1 answer

How to use model validation/data annotation in dynamic virtual view in asp.net mvc

I found some posts about how to create a dynamic virtual view using custom virtual path provider. Here is the post But I would like to know how to implement data annotation in that virtual view. Or what is the best pattern to do validation on…
0
votes
0 answers

Cross-table validation in ASP .NET MVC

I'm peforming validation using DataAnnotations and Validation Attributes. I'm using ADO NET Entity Model, Domain Services, RIA Services, Silverlight and my projet has a server side that's in ASP .NET. I want to perform cross-table validation, how…
0
votes
2 answers

Feeding DataAnnotations.ValidationAttribute error messages with resource stored string value pairs

My ValidationAttributes don't access my ErrorMessages value-pairs stored in a .resx Resource File generated with VS2010 built in resource generator. (Add New Item - Resources File) I simply added a folder named Resources, then added a new Resources…
-1
votes
1 answer

ValidationResult to send 409 conflict status code ASP.NET Core Web Api

Is it possible to send HttpStatusCode.Conflict(409) from ValidationResult method of System.ComponentModel.DataAnnotations By default it is returning HttpStatusCode.BadRequest(400). is there any possible way to send different status codes with…
-1
votes
2 answers

MVC Remote Validation Not calling function or working

MVC Remote Validation not working, I'm new to MVC, any help is appreciated: WebConfig: Controller: …
a ridi
  • 125
  • 2
  • 13
-1
votes
1 answer

Custom date RangeAttribute will return exception on negative values for year,month and day

I created a custom DateRange attribute to check for maximum and minimum value for date. this is the code public class DateRangeAttribute : RangeAttribute { public DateRangeAttribute(int minimumYear, int minimumMonth, int minimumDay, int…
Sara N
  • 1,079
  • 5
  • 17
  • 45
-1
votes
1 answer

How to make INotifyDataErrorInfo errors persistent until corrected?

My validation works in the first instance but when I go from one Tab Item to another and back again the validation is gone. I would have expected this state to be persistent until the user inputs the valid passing criteria in this scenario. Maybe…
metoyou
  • 639
  • 1
  • 7
  • 22
-1
votes
1 answer

pass value to attribute based on received value

Im using C# 4.5 web api type project. When receiving HttpPost requests from clients i want to validate the request fields. The issue is that the input validation is depended on the input itself, or to be more specific, depends on provided…
Ori Refael
  • 2,888
  • 3
  • 37
  • 68
-1
votes
1 answer

.NET MVC error client side with custom validation attribute

I have written a very simple custom validation attribute to check for an alphanumeric string and it is working server side, but I get a NullReferenceException for validationContext when trying to use the client side model validation in .NET MVC. My…
-1
votes
2 answers

Autofac and DI for ValidationAttribute

I have the following validation attribute class: public class ZipCodeValidationAttribute : ValidationAttribute { private readonly IValidationRepository _repository; public override bool IsValid(object value) { var repository =…
1 2 3
11
12