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

MVC5 ModelClientValidationRegexRule always failing

In my custom validation attribute I Have the following: yield return new ModelClientValidationRegexRule(_invalidCharactersErrorMessage, "/^[A-Za-z0-9\\s]+$/i"); It is suppose to accept only letters, numbers and spaces. Now on the HTML side of…
Bagzli
  • 6,254
  • 17
  • 80
  • 163
1
vote
1 answer

Add custom html attribute through validation attribute

In mvc5 whenever you use [MaxLength(10)] attribute it generates the following html attribute: `data-val-maxlength="The field Email must be a string or array type with a maximum length of '10'." This is nice and useful and all but what I wish to do…
Bagzli
  • 6,254
  • 17
  • 80
  • 163
1
vote
0 answers

ASP.Net MVC Custom client side validation not firing

i have the below jquery unobtrusive code which is not firing. $.validator.unobtrusive.adapters.add('customvalidation', ['productname'], function (options) { options.rules['customvalidation'] = { productname: options.params.productname…
Mou
  • 15,673
  • 43
  • 156
  • 275
1
vote
1 answer

Autofac inject into ValidationAttribute on WebApi and OWIN

There's a few posts on SO relating to the work around for allowing autofac injections with ValidationAttribute 's (Asp.Net MVC3: Set custom IServiceProvider in ValidationContext so validators can resolve services) but I'm using OWIN and WebApi so…
johnnyboy
  • 869
  • 12
  • 23
1
vote
0 answers

Combine custom validation attribute with formatting

I have a metadata class for my Customer where I validate the PurchaseDate. The first annotation (DataType) is for formatting the date in an EditorFor, to show just the date part. The second annotation is a custom validation to verify that the value…
Niklas
  • 13,005
  • 23
  • 79
  • 119
1
vote
0 answers

Asp.Net Mvc how to Conditional Validation

I'm trying to build a demo application for gain Asp.Net Mvc 5 development experience. In these days i'm trying to build a site settings. I've a model named Settings. And there are properties like below. public int PasswordRequiredLength { get;…
1
vote
1 answer

Custom ValidationAttribute in NancyFX Is Not Being Recognized or Used

I have specified a custom NonEmptyGuidAttribute which extends ValidationAttribute and looks like the following public class NonEmptyGuidAttribute:ValidationAttribute { public override bool IsValid(object value) { Guid parsedValue =…
TheJediCowboy
  • 8,924
  • 28
  • 136
  • 208
1
vote
0 answers

Validation attribute depending on object instance type

I'm facing a conception problem. We could create and update our deals in two ways : using web forms (one to create deals, another one to edit them) and through an integration file (to allow mass creation & update). public class…
1
vote
1 answer

Get value inside custom validation attribute?

DI've created two custom validation attributes. After I've done the date validation I want to do the time validation, but to do that I need MyDate. How can I reach MyDate from inside the time validation? My model: [DateValidation()] public DateTime…
Mangs
  • 698
  • 1
  • 19
  • 40
1
vote
0 answers

Data annotation mapping to the property of the object

I'm sorry if the title is not representative enough. So in my case, I want to build a more dynamic search form. Previously my search form only support equal operator. Now I want it to support another operators (contains, greater than etc). This is…
Moch Yusup
  • 1,266
  • 14
  • 14
1
vote
2 answers

MVC RequiredIf Attribute - IsValid value parameter always null

I am implementing a RequiredIf validation attribute and the value being passed to the IsValid method is always null. RequiredIfAttribute Class public class RequiredIfAttribute : ValidationAttribute { private RequiredAttribute innerAttribute…
user2166297
1
vote
2 answers

C# Unable to validate property using a custom validate attribute

I have a validation class: public sealed class ValidationSet : ValidationAttribute { private List _set = new List(); public ValidationSet(params string[] setOfValues) { _set = setOfValues.ToList(); } …
jamesdeath123
  • 4,268
  • 11
  • 52
  • 93
1
vote
0 answers

Custom ValidationAttribute in PartialView not showing error messages

I did a prof of concept of a custom validation usign ValidationAttribute in an mVC simple site, validating a date range. Only interested in that finishDate was before startDate. And everything worked fine. Well, I have no client validation but the…
1
vote
1 answer

Contacting database from within data validation attribute

I have a clientside typeahead that pulls back a json list and presents options to the user for a specific list of places that they can enter for an input field. On the server I want to make sure that the submitted form data matches one of these…
Neil
  • 5,179
  • 8
  • 48
  • 87
1
vote
0 answers

pass parameters to a custom validation attribute

hi im trying to create the next simple custom validation: public class EnteroDistintoDeAttribute : ValidationAttribute, IClientValidatable { public int entero { set; get; } public EnteroDistintoDeAttribute(int entero) { …
EricGS
  • 1,323
  • 2
  • 17
  • 42