I created database and add a table using code first workflow and then created ADO.NET Entity data model, when I do that it automatically generated model class for the table in that database,
within that model class its defined Password Field but not Confirm Password field since I don't want store both,
HERE code snippet in my Model class
[Required(ErrorMessage = "Please provide Password", AllowEmptyStrings = false)]
[DataType(System.ComponentModel.DataAnnotations.DataType.Password)]
[StringLength(255, MinimumLength = 5, ErrorMessage = "Password must be 5 char long.")]
public string Password { get; set; }
public string PasswordSalt { get; set; }
to compare above two field I just try to use java script front end validation
I just want to know how to compare Password Field and Confirm Password Field using JavaScript in cshtml I already tried many ways to do this ,but still cannot figure it out ,
This is the code snippet I added overs the cshtml file
<script src="../../Scripts/jquery-1.7.1.min.js" type="text/javascript">
$(function isPasswordSame() {
var password = document.getElementById('password');
var confirmPassword = document.getElementById('passsword-confirm');
return password === confirmPassword;
});
</script>
this is the CSHTML body definition of above model class
<div class="editor-label">
@Html.LabelFor(model => model.Password)
</div>
<div id="password" class="editor-field">
@Html.EditorFor(model => model.Password)
@Html.ValidationMessageFor(model => model.Password)
</div>
<div class="editor-label">
<label> Confirm Password</label>
</div>
<div class="editor-field">
<input type="password" id="passsword-confirm"/>
</div>
but this not working properly .looking for good overcome solution or any enhancement , Thanks
HERE the Full CSHTML code
@model AFFEMS2_HEC.Models.HEI_REG_TABLE
@{
ViewBag.Title = "HEI_Registration";
Layout = "~/Views/Shared/Login_Layout.cshtml";
}
<script src="../../Scripts/jquery-1.7.1.min.js" type="text/javascript">
$(function isPasswordSame() {
var password = document.getElementById('password');
var confirmPassword = document.getElementById('passsword-confirm');
return password === confirmPassword;
});
</script>
<script type="text/jscript"></script>
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>User</legend>
@Html.AntiForgeryToken()
@if (ViewBag.Message != null)
{
<div style="border:solid 1px green">
@ViewBag.Message
</div>
}
<div class="editor-label">
@Html.LabelFor(model => model.HEI_ID)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.HEI_ID)
@Html.ValidationMessageFor(model => model.HEI_ID)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Username)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Username)
@Html.ValidationMessageFor(model => model.Username)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Password)
</div>
<div id="password" class="editor-field">
@Html.EditorFor(model => model.Password)
@Html.ValidationMessageFor(model => model.Password)
</div>
<div class="editor-label">
</div>
<div id="passsword-confirm" class="editor-field">
<input type="password" />
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}