Questions tagged [data-annotations]

Data Annotations are used by frameworks such as ASP.NET MVC to enable a model-based validation approach and enforce consistent validation throughout the application, both on client and server side. They were first introduced in ASP.NET MVC 2. In addition to ASP.NET MVC, they can also be used with other technologies such as Entity Framework, either through manual placement of attributes on properties, or automatic generation with T4 templates.

3030 questions
1
vote
1 answer

Partially validate model property using data annotation

I Have set two validation on model property using Data Annotation, like below: [MinLength(8, ErrorMessage = "Password Requires at least one letter, one number and 8 characters long")] [Required(ErrorMessage = "Password Required")] public string…
Harshad Vekariya
  • 972
  • 1
  • 7
  • 28
1
vote
0 answers

Is there an annotation in c# that translates to plain text documentation via OData v4

I am using odata v4 (System.Web.OData) to provide a rest interface to some code first models. I am using c# annotations to provide additional information about the models (ranges, required etc) however I would love to be able to add plain text…
Digital Powers
  • 460
  • 6
  • 23
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

Data Annotations not working?

Hi my mvc class include Data Annotation [Index] but After updating the visual studio, my [Index] Data Annotation not working and not working unique. How i am fixed that code ? public class MaterialSupplier { public int MaterialSupplierID { get;…
user5125733
1
vote
2 answers

How to add Custom logic for validation using asp.net mvc data annotations?

I have read this before about asp.net mvc validations but does not mention what i want to do,So have this view model - public class MyViewModel { [StringLength(200, MinimumLength = 2, ErrorMessage = "Invalid Name")] public string…
Vishal
  • 12,133
  • 17
  • 82
  • 128
1
vote
1 answer

Validating Multiple Fields (Datetime and Bool) in Data Annotation Model on Submit

Currently I'm working on a MVC 3 Environment and I need to add a Validation that validates 2 Fields in Dataannotation Models just like the validation of [Required(ErrorMessage="Required!")] that is triggered onsubmit. Currently , The Validation…
Enrique Gil
  • 754
  • 4
  • 19
  • 50
1
vote
1 answer

Why to use Foolproof validation in ASP.NET MVC 2 and DataAnnotations 4?

I understand that Foolproof validation extends DA and adds support for validation attributes as listed here However, most of the validations that are listed can be in theory be accomplished by writing custom validators. Why would I need to use this…
Nick
  • 7,475
  • 18
  • 77
  • 128
1
vote
0 answers

Non Ascii characters in data annotations with Entity Framework

I'm trying to add some validation checks to my model in MVC web application like this: [Display(Name = "Şube")] public decimal BranchId { get; set; } But non ascii characters like "ş, ğ" doesn't render correctly. I don't have any similar…
1
vote
0 answers

How to use asp.net DataAnnotations with jquery.toast

My project has the standard jquery.toast alerts. I would use the asp.net DataAnnotations to validate the fields, but keeping the toast to view messages, someone would know if it's possible? Examples: cs public class…
1
vote
1 answer

non-static ErrorMessage data annotation in MVC

I have a site which can be opened in multiple languages, the strings from the site are retrieved from a XML file which is provided by the product owner. The model contains many fields but for this question we are just looking at FamilyName public…
ObiEff
  • 640
  • 8
  • 24
1
vote
2 answers

Intent of Data Annotations Model Binder

The article here mentions the use of Data Annotations Model Binder that is available here. Does anyone know what it's intent is? To do DA validation, I don't need a special Model binder in MVC 2.0
Nick
  • 7,475
  • 18
  • 77
  • 128
1
vote
1 answer

Django 1.8: Annotation of the queryset members count WITHOUT filtering

How can I use the Django 1.8 ORM to count, how many members an object has? For example: How can I SORT all workers by the count of the software, their company is using? Bill 3 (Windows, Office, Visio) Tom 2 (Windows, Office) Anton 1…
1
vote
0 answers

What is the Razor syntax to dynamically require an Html.TextBoxFor based on specified conditions?

I've got a form where a description field will be required in some situations, and not required in others. Originally, it was always required and I had the required attribute in the model, like…
Ken Palmer
  • 2,355
  • 5
  • 37
  • 57
1
vote
1 answer

Can I change the width of an EditorFor with data annotations?

There's a few questions on similar topics. However, they don't actually address my issue. DisplayFormat for TextBoxFor in MVC Display a formatted date in an EditorFor() ASP.NET MVC EditorFor DateTime I've been searching and reading up and cannot…
user3956566
1
vote
1 answer

Implementing a class-level validation attribute that writes to a property inside the class

I'm building an ASP.NET MVC site where I want to decorate my ViewModels with validation attributes. One of the things I want to validate is that the address that a user submits through a form is geocodable. For that, I have already created a custom…
Maxim Zaslavsky
  • 17,787
  • 30
  • 107
  • 173
1 2 3
99
100