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

C# Hide base property in Attributes

I created a new attribute that inherits from ValidationAttributes, see code below: public class BaseValidationAttribute : ValidationAttribute { public string ShortNameKey { get; set; } public string DescriptionKey { get; set; } …
0
votes
1 answer

ValidationAttribute injecting services for unobtrusive client validation

I have a relatively simple ValidationAttribute which requires some services in order to complete the IsValid method - basically just retrieving a list of IDs to compare the selected value against. As suggested by this post here, I am using the…
nat
  • 2,185
  • 5
  • 32
  • 64
0
votes
1 answer

Validate private properties using ValidationAttributes in .net 4

I have classes which get private properties set via the constructor. I would then like to run the following code from a base class to check if the passed values are ok: ValidationContext context = new ValidationContext(this, null,…
AyKarsi
  • 9,435
  • 10
  • 54
  • 92
0
votes
0 answers

Using custom validation attributes in ASP.NET MVC

I'm trying to create a custom validation attribute to apply it. I was using the tutorial: http://ezzylearning.com/tutorial/creating-custom-validation-attribute-in-asp-net-mvc (didn't implement the client side validation. Everything before the client…
AOY
  • 355
  • 3
  • 22
0
votes
1 answer

How to access property of parent in validation attribute

In my code below I want to check with AttributeValidation if a field is given dependent on a property of its parent element. The comment in the class RequiredIfParentState1 describes my question best. public class ChildModel() { …
0
votes
1 answer

Custom validate attribute on query parameter web api

I have the following controller which takes guids in string format as query parameters. I wanted to verify they were a valid guid before executing the method but I'm not sure how to fire my custom ValidationAttribute: controller.cs public async…
TomSelleck
  • 6,706
  • 22
  • 82
  • 151
0
votes
2 answers

CustomValidationAttribute doesn't work when other attributes are applied to the class

Reproduction: Imports System.ComponentModel Imports System.ComponentModel.DataAnnotations Module Module1 Sub Main() Dim type = GetType(Contact) TypeDescriptor.AddProviderTransparent( New…
Shimmy Weitzhandler
  • 101,809
  • 122
  • 424
  • 632
0
votes
1 answer

Custom validation attribute not working after publishing

Recently I been hand on a MVC project, and I required to make an custom validation attribute for certain model, [AttributeUsage(AttributeTargets.Property)] public class TimeGreaterThanAttribute : ValidationAttribute { public…
Dean
  • 668
  • 12
  • 32
0
votes
3 answers

Securing against JS injection with ASP.NET MVC

I would like to allow users to post HTML to a site but need to ensure that no Javascript is injected into the site. So far I have created a validation attribute to check the incoming html for dodgy doings [AttributeUsage(AttributeTargets.Property, …
Anthony Johnston
  • 9,405
  • 4
  • 46
  • 57
0
votes
2 answers

Custom API ValidationAttribute for class property

I have a class Student that contains the list of property 'TextPair' as shown below: public class Student { public List Hobbies { get; set; } public List Languages { get; set; } public List Majors { get;…
OmGanesh
  • 952
  • 1
  • 12
  • 24
0
votes
0 answers

ValidationAttribute Custom

I'm a little new in MVC and I'm needing to validate a field by checking where the field can not have the value Espécifico NotFound as an example, could someone give me a suggestion of how to do? I tried to elaborate a custom validation, but it does…
0
votes
1 answer

FileExtensions attribute - using Enumerator as a parameter

Long story short - I have an Entity Framework model which accepts Enum type property: public class FileUploads { public AllowedFileTypes FileType { get; set; } } Enum is: public enum AllowedFileTypes { jpg, png, gif, jpeg, …
Alex
  • 4,607
  • 9
  • 61
  • 99
0
votes
1 answer

Identity system User is always null in the action method of custom remote validation attribute in ASP.NET MVC

I am developing an Asp.net mvc web application. In my application, I need to implement, custom remote validation attribute. I can implement it successfully. But it is having problem with User of identity system in controller action method that is…
0
votes
1 answer

ASP MVC 5 Custom Validation Attribute to Compare Two Properties?

I have the following custom validation attribute to check if two properties are not the same but its applied to the entire model: [AttributeUsage(AttributeTargets.Class)] public class ValidateUser : ValidationAttribute { public override bool…
adam78
  • 9,668
  • 24
  • 96
  • 207
0
votes
0 answers

Custom remote validation attribute throwing error at server side in ASP.NET MVC

I am developing an ASP.NET MVC Web Application. In my project I am doing remote validation using data annotation to my view model class. I know default remote attribute does not support server validation. I can validate it again in action method.…