Click here to Skip to main content
15,880,796 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
I am first using vs2012 and mvc3.

but what's the problem with compare attribute. I wrote the following code.


C#
[Required]
       [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
       [DataType(DataType.Password)]
       [Display(Name = "Password")]
       public string Password { get; set; }

       [DataType(DataType.Password)]
       [Display(Name = "Confirm password")]
       [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
       public string ConfirmPassword { get; set; }




and the heading contain :

C#
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Web.Mvc;
using System.Web.Security;



There is no problem with DataType and Display attribute, but what wrong with compare attribute.

[edit]SHOUTING removed - OriginalGriff[/edit]
Posted
Updated 2-Jun-14 23:54pm
v4
Comments
OriginalGriff 3-Jun-14 5:31am    
DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalisation if you want to be taken seriously.
rayhan12345 3-Jun-14 5:38am    
Sorry!! I didn't know that. extremely sorry for that.
OriginalGriff 3-Jun-14 5:41am    
It's normal Netiquette:
http://en.wikipedia.org/wiki/Etiquette_in_technology
ArunRajendra 3-Jun-14 5:41am    
What's the error?
Prasad Avunoori 3-Jun-14 5:43am    
Do you have NewPassword property?

1 solution

Please try is as below.Use CompareAttribute.

Note:This is just a sample.Adjust it according to your app. :)

C#
public string EmailAddress {get; set;}

[CompareAttribute("EmailAddress", ErrorMessage = "Emails mismatch")]
public string VerifiedEmailAddress { get; set; }


Check here for more : CompareAttribute
 
Share this answer
 
Comments
rayhan12345 3-Jun-14 6:04am    
Thanks!! I got it.
Sampath Lokuge 3-Jun-14 6:20am    
Glad to hear that it helped! :)
DamithSL 5-Jun-14 9:48am    
my5!
Sampath Lokuge 5-Jun-14 9:58am    
Thanks DamithSL. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900