Click here to Skip to main content
15,886,362 members
Everything / DataAnnotation

DataAnnotation

DataAnnotation

Great Reads

by kr.is
How to create a simple validation attribute using C#
by Kelum Priyadarshane
This project developed using combination of Entity Framework 6.0 + Code First Approach + Web API 2 + Repository Pattern + ASP.NET MVC 5 + SQL Server 2012 + Unit of Work Testing + Bootstrap.
by Web Technobrat
A quick walkthrough for implementing client and server side validations in a variety of ways in ASP.NET MVC projects.
by Shivprasad koirala
In this short article, we will discuss how C# DataAnnotation library helps us to do validations.

Latest Articles

by kr.is
How to create a simple validation attribute using C#
by Kelum Priyadarshane
This project developed using combination of Entity Framework 6.0 + Code First Approach + Web API 2 + Repository Pattern + ASP.NET MVC 5 + SQL Server 2012 + Unit of Work Testing + Bootstrap.
by Web Technobrat
A quick walkthrough for implementing client and server side validations in a variety of ways in ASP.NET MVC projects.
by Shivprasad koirala
In this short article, we will discuss how C# DataAnnotation library helps us to do validations.

All Articles

Sort by Score

DataAnnotation 

21 Jan 2020 by kr.is
How to create a simple validation attribute using C#
19 Aug 2018 by ganesh.dks
Hi, I am fairly new with Hands On MVC, So I wanted to know if there is a simple solution to my problem. I have a model class whose scaled down version is given below : - public class Driver { public int ID { get; set; } [Required] [Display(Name = "Name")] public string FName {...
21 Jan 2020 by phil.o
Data Mining[^] Being able to do your own research is a skill which you should aim to acquire as soon as possible. And, like every skill, you only can obtain it by practicing.
14 Jun 2013 by vishnutejcj
HiI am stuck with this tricky problem.I've a control whose visibility will be set based on user role. In this case i can't set this property as required.[Required(ErrorMessage = Client Name is required)][Display(Name ="Client Name")]public string SelectedClientName { get; set;...
14 Jun 2013 by Dave Kreskowiak
You can see if this[^] helps.If not, there's a bunch more options if you Google for "mvc dynamic required field[^]".
20 Jun 2013 by samadhan_kshirsagar
hi please visit this linkhttp://stackoverflow.com/questions/14321815/mvc4-data-annotation-validation-based-on-different-user-roles-using-entity-frame[^]
23 Jun 2013 by Jameel VM
Go through this linkhttp://amanek.com/building-data-annotations-validator-control-with-client-side-validation/[^]Hope this helps
24 Jun 2013 by shivammpi123
Can you show me your view code....It should be like this view code@using (@Html.BeginForm("ImportContacts", "Outlook", FormMethod.Post, new { id = "Importform" })){ @Html.ValidationSummary(true, "Please fill the form correctly and try again."); ...
12 Aug 2014 by Fatihx
I code a project with ASP.NET MVC using Entity Framework. I have acontroller which has one action(Save action which commit changes to database).I want to bypass "Answer" property out of validation without using DataAnnotations. In View, i tried some code but i failed. Because of my dynamic...
12 Aug 2014 by Manoj B. Kalla
Dear Fatihx,Just remove a [Required . . line from above public string AnswerYour clientside validation would be goes off.If, this is your solution, you are looking for then select as answer.Thank You.Manoj Kalla
12 Aug 2014 by Manoj B. Kalla
Dear Fatihx,For other page you have to write in GET/POST method, check as per your situation.ModelState.Remove("Answer")sure, it will work.Thank You.Manoj Kalla
13 Aug 2014 by NowYouSeeMe
the ideal way is to use viewmodeleg:public Answer{ [Key] public int AnswerId { get; set; } public int QuestionId { get; set; } public int CompanyId { get; set; } [Required(ErrorMessage = "***")] public string Answer { get; set;...
20 Aug 2014 by mymina
hi alli have a project in wpf that use Sql Server and Entity Framework Database First.And for crud in database, i'm force use stored procedure.now,for validation data:i do'nt know how to use in classes.please help me for validation property with stored procedure.
15 Oct 2014 by Nimit Joshi
I want to apply multiple data annotation on a property named Year.Following is my code:[Required(Error Message="Year is Required")][Range(1900, 2050, ErrorMessage = "Enter the Valid Year")]public string YearWhen i enter an invalid year then it is working fine but when i do not...
10 Jun 2015 by Ben J. Boyle
Couple of options:1) Make your model class inherit from IValidatableObject and implement the validate method, see https://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.ivalidatableobject.aspx[^]That though is not using the Data Annotations, but...2)...
28 Dec 2020 by Member 12021470
I have a Remote attribute on the ProductCode property of Product model. When I create a new Product it works perfect and tells the user that an ProductCode is already in use. Now I'm having a problem in my editing form (if the user wants to updates values). It tells the user that his/her...
4 Mar 2016 by Member 1966294
In the View Add Hidden field@Html.Hidden(initialProductCode, Model.ProductCode)In the Remote attribute Add AdditionalFields[Remote("ValidateProductcode", "Controller", ErrorMessage = "Product Code already exists.", AdditionalFields = "initialProductcode")]and the Controller action...
18 Mar 2020 by OriginalGriff
Try getting rid of the spurious whitespace, escape the "reserv ed characters" and start your email with a "start of text" marker: [a - z0 - 9._ % +-] +@[a-z0-9.-]+\.[a-z]{2,}$ Becomes^[a-z0-9\._%+\-]+@[a-z0-9\.\-]+\.[a-z]{2,}$
4 May 2020 by Abhishek Duppati
An alternative for Data Annotations in MVC would be the Validation Application Block. We can consider using the Validation Application Block if we want to encapsulate validation good practice into easily maintainable code that can be reused. With...
31 Jul 2020 by gcogco10
Hi Team I want to validate when leaving the textbox on my form, but i able to validate on a client side, i havent experience using data-anotation in asp.net and need bit of a help. When leaving the textbox if its empty must validate using...
31 Jul 2020 by Jin Vincent Necesario
Hi, You can easily use the regular expression attribute and set the expression inside that attribute and it should be on top of a property of a class. [RegularExpression ("[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$", ErrorMessage = "Invalid...
25 Sep 2020 by Member 14908411
I am using Expressive annotations to handle RequiredIf conndition My Model [RequiredIf("IsSellable == false", ErrorMessage ="Offer code is required!")] public string Code { get; set; } public bool IsSellable { get; set; } whenever I click...
25 Sep 2020 by BillWoodruff
From the Expressive Annotations GitHub : [^]Quote: RequiredIf attribute is not working, what is wrong? Make sure RequiredIf is applied to a field which accepts null values. In the other words, it is redundant to apply this attribute to a field...
N 24 Apr 2024 by Member 11307750
the required validation not working in mvc,After creating the view ,when i click on the submit button,no response from the form What I have tried: using System.ComponentModel.DataAnnotations; namespace Trial.Models { public class Product ...
N 24 Apr 2024 by Pete O'Hanlon
Try changing your Required annotation to Required(AllowEmptyStrings=false) to take care of situations where the string is an empty string.
24 Oct 2016 by Kelum Priyadarshane
This project developed using combination of Entity Framework 6.0 + Code First Approach + Web API 2 + Repository Pattern + ASP.NET MVC 5 + SQL Server 2012 + Unit of Work Testing + Bootstrap.
27 Sep 2015 by Web Technobrat
A quick walkthrough for implementing client and server side validations in a variety of ways in ASP.NET MVC projects.
11 May 2015 by Shivprasad koirala
In this short article, we will discuss how C# DataAnnotation library helps us to do validations.
6 Feb 2015 by ogomerub
ViewModel base for all ViewModels. Validation system with DataAnnotations and IDataErrorInfo
3 May 2013 by gicalle75
question: how can you keep things DRY by only applying metadata information for dataannotations and validation on the master class, and then reuse this on the viewmodels?example:class book (domain model) and the metadataImports...
16 Apr 2014 by medessad
I am developping an application with ASP .Net MVC 4 which is french language based, almost of the treatements i have in my app, are based on dates.For the date textfield i use jQuery DatePicker and i disable hand modifyig fields.In my Model, i add[DataType(DataType.Date)]But when...
15 Oct 2014 by Nelek
From the few code you have posted, it is difficult to know exactly where the error comes. As I can see your "Year" is a String, so you are probably converting it to int when entered, so you can validate with your range.Some possiblities that I can imagine:- If the string is empty, the...
26 May 2015 by _Asif_
Try this "\d+(\.\d+)?". You can find plenty of examples over the net. Just Google!
21 Jan 2020 by Patrice T
Quote: no. i do not found relevant answer.i do not found most appropriate answer. You need to learn to cope with search engines, if something is on internet, they know. Wikipedia is a good place to search too. Data mining - Wikipedia[^]
21 Jan 2020 by zamsha javed
what is meant by data mining? what are application where data mining concepts are applied? what is scope of data mining? What I have tried: no. i do not found relevant answer.i do not found most appropriate answer.
23 Jun 2013 by naikotiarun
Hi.,I am new to Entity Framework, I have created a EDM using Model first appraoch and applied validations using datannotations, everything is working fine but all the validations are displayed at one place but i would like to show validation error messages beside the respective field.The...
26 May 2015 by Amit Samnani
Hi,everyone Question: i have one text-box and i want to allow only numeric value to this text-box like i.e .2,2.3,23.233 Solution: For the above, i already try regex ("^\s*(?=.*[1-9])\d*(?:\.\d{1,4})?\s*$")but still it can`t be allow after point value like...
26 May 2015 by Bernhard Hiller
Better usedouble val;if (double.TryParse(YourTextbox.Text, out val)){ //OK}else{ //not numeric}That strategy will also cope with different regional settings (what about a decimal comma instead of a decimal point?).
2 Jul 2015 by SDavisworth
HelloI'm using Data Annotation in a Calburn Micro framework to validate my user input. User selects a date that needs to be 3 days in the future. Record is saved to db. 4 days later the record is opened again and validation kicks in on the selected date. What I need to do is turn off...
10 Jun 2015 by Adil S
I was asked a question in an interview regarding validation with data annotations in MVC.I have a drop down list and two text boxes.If some value is selected from the drop down (say "XYZ"), then the apply validation on textboxes to be required else, textboxes can be left blank on...
18 Mar 2020 by gcogco10
Hi Team im creating mvc asp.net form, i have model and view to do this for my email .But the problem my email textbox is not validating and have used data annotation from model side and view side i have this logic below. Please help me mates to...