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....
Refer below code. [Required(ErrorMessage = "Password is required." )] [Required(ErrorMessage = "Confirmation Password is required." )] [Compare( "Password" , ErrorMessage = "Password and Confirmation Password must match." )]
c# - Data Annotation to validate confirm password - Stack Overflow.
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.
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.
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; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With