Click here to Skip to main content
15,899,124 members

Ankur Ramanuj - Professional Profile



Summary

Follow on Twitter      Blog RSS
174
Authority
6
Debator
4
Editor
22
Enquirer
181
Organiser
800
Participant
0
Author
I have over 10 years of experience working with Microsoft technologies.I'm a highly motivated self-starter with an aptitude for learning new skills quickly

Reputation

Weekly Data. Recent events may not appear immediately. For information on Reputation please see the FAQ.

Privileges

Members need to achieve at least one of the given member levels in the given reputation categories in order to perform a given action. For example, to store personal files in your account area you will need to achieve Platinum level in either the Author or Authority category. The "If Owner" column means that owners of an item automatically have the privilege. The member types column lists member types who gain the privilege regardless of their reputation level.

ActionAuthorAuthorityDebatorEditorEnquirerOrganiserParticipantIf OwnerMember Types
Have no restrictions on voting frequencysilversilversilversilver
Bypass spam checks when posting contentsilversilversilversilversilversilvergoldSubEditor, Mentor, Protector, Editor
Store personal files in your account areaplatinumplatinumSubEditor, Editor
Have live hyperlinks in your profilebronzebronzebronzebronzebronzebronzesilverSubEditor, Protector, Editor
Have the ability to include a biography in your profilebronzebronzebronzebronzebronzebronzesilverSubEditor, Protector, Editor
Edit a Question in Q&AsilversilversilversilverYesSubEditor, Protector, Editor
Edit an Answer in Q&AsilversilversilversilverYesSubEditor, Protector, Editor
Delete a Question in Q&AYesSubEditor, Protector, Editor
Delete an Answer in Q&AYesSubEditor, Protector, Editor
Report an ArticlesilversilversilversilverSubEditor, Mentor, Protector, Editor
Approve/Disapprove a pending ArticlegoldgoldgoldgoldSubEditor, Mentor, Protector, Editor
Edit other members' articlesSubEditor, Protector, Editor
Create an article without requiring moderationplatinumSubEditor, Mentor, Protector, Editor
Approve/Disapprove a pending QuestionProtector
Approve/Disapprove a pending AnswerProtector
Report a forum messagesilversilverbronzeProtector, Editor
Approve/Disapprove a pending Forum MessageProtector
Have the ability to send direct emails to members in the forumsProtector
Create a new tagsilversilversilversilver
Modify a tagsilversilversilversilver

Actions with a green tick can be performed by this member.


 
GeneralHow To Perform Custom Validation Using Validation Attribute In ASP.NET MVC Pin
Ankur Ramanuj24-Jan-18 20:36
Ankur Ramanuj24-Jan-18 20:36 
Let us see how to do it.

Step 1

First of all create ASP.NET MVC app with the name MyApp.

Step 2

Add folder with the name Validator in your Application.

Step 3

Inside the folder, add class with the name FirstNameValidator.

Now, derive this FirstNameValidator class from ValidationAttribute class and execute the code given below in order to perform validation on FirstName model field.

C#
//add this namespace  
using System.ComponentModel.DataAnnotations;  
namespace MyApp.Models {  
    public class FirstNameValidator: ValidationAttribute {  
        protected override ValidationResult IsValid(object value, ValidationContext validationContext) {  
            if (value != String.Empty) {  
                return ValidationResult.Success;  
            } else {  
                return new ValidationResult("First Name is required!!!");  
            }  
        }  
    }  
}  


Step 4

Now, in your model, add this FirstNameValidator attribute to model field in order to fire validation against the model field.

C#
using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Web;  
using System.ComponentModel.DataAnnotations;  
//add below line   
using MyApp.Validator;  
namespace MyApp.Models {  
    public class TestModel {  
        [FirstNameValidator]  
        public string FirstName {  
            get;  
            set;  
        }  
        public string Email {  
            get;  
            set;  
        }  
    }  
}  


Summary

When the user submits the data without entering information in First Name field, it is going to fire and First Name is required.

modified 22-Jan-20 4:13am.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.