Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compare password and confirm password in ASP.Net MVC

Is it possible to compare confirm password textbox's text with @Html.PasswordFor(model=>model.Password)?

@using (Html.BeginForm())
{
    <table>

        <tr>
            <td>@Html.LabelFor(model => model.Password)</td>
            <td>@Html.PasswordFor(model => model.Password)</td>
            <td>@Html.ValidationMessageFor(model => model.Password)</td>
        </tr>
        @*Here I want to take "Confirm Password" and want to compare it with "Password" in View(.cshtml only) as
          I have not taken ConfirmPassword in my model.*@
        <tr>
            <td>
                <input type="submit" value="Create" />
            </td>
        </tr>
    </table>              
}

Please suggest any way or solution,

How to compare password and confirm password without getting confirm password property in Model. Thanks....

like image 206
Vishal Hirapara Avatar asked Feb 13 '14 06:02

Vishal Hirapara


People also ask

How can I compare password and confirm password in ASP NET MVC?

Refer below code. [Required(ErrorMessage = "Password is required." )] [Required(ErrorMessage = "Confirmation Password is required." )] [Compare( "Password" , ErrorMessage = "Password and Confirmation Password must match." )]

What annotation must be used for comparing passwords in MVC?

c# - Data Annotation to validate confirm password - Stack Overflow.

What are data annotations in MVC?

In ASP.NET MVC, Data Annotation is used for data validation for developing web-based applications. We can quickly apply validation with the help of data annotation attribute classes over model classes.

What is ASP validation for?

ASP.NET validation controls validate the user input data to ensure that useless, unauthenticated, or contradictory data don't get stored. ASP.NET provides the following validation controls: RequiredFieldValidator. RangeValidator.


1 Answers

Using Compare DataAnnotation it will be easy to compare password but if model genrate from database use NotMapped, NotMapped Properties In An Entity Framework Using A Code-First Strategy

[Required]
public string Password { get; set; }

[NotMapped] // Does not effect with your database
[Compare("Password")]
public string ConfirmPassword { get; set; }
like image 152
Sender Avatar answered Oct 05 '22 13:10

Sender