我正在为一个在后端数据库中更新用户密码的网站开发密码重置功能。我可以通过输入强密码(即 Password123)成功更改用户密码!当输入的密码不够弱时,MVC 架构非常高兴,即 abc,但是当我输入不匹配的密码和确认时,即 Password123!和密码1234!然后我收到与以下行的对象引用错误相关的错误:
@using (Html.BeginForm("Reset", "Reset", new { qString = Model.QueryString } ))
这是我的完整代码:
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
@model ......ResetModel
<script type="text/javascript">
$(document).ready(function () {
$('#close').click(function (event) {
closeAjax();
event.cancelBubble = true;
event.returnValue = false;
event.preventDefault();
event.stopPropagation();
});
});
$(document).ready(function () {
$("#index").validate({
rules: {
password: {
required: true, minlength: 6
},
confirmpassword: {
required: true, equalTo: "#password", minlength: 6
}
},
messages: {
password: "Please enter your new password.",
c_password: "Please confirm your new password."
}
});
});
</script>
<div class="form_container">
<div class="logo">
<a href=""><img class="logo" src="@Url.Content("~/Content/SP_Logo_white.png")" alt="Cloud"/></a>
</div>
<div class="reset">
<h3>Password Reset</h3>
<div class="reset-help">
<p>Forgot your password? Use the form to change or reset your password.</p>
</div>
@using (Html.BeginForm("Reset", "Reset", new { qString = Model.QueryString } ))
{
<label for="reset">UserName:</label>
<input type="text" id="username" name="username" /><br />
<label for="password">New Password:</label>
<input type="password" id="password" name="password" /><br />
<label for="confirmpassword">Confirm Password:</label>
<input type="password" id="confirmpassword" name="confirmpassword" />
<p><input type="submit" id="submit" value="Submit" /></p>
}
</div>
</div>
有人可以帮我理解为什么只有当密码不匹配时才会发生这种情况,我也无法理解为什么我的javascript验证没有被设置
渲染的 HTML 如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Password Reset</title>
<link href="/Content/Site.css" rel="stylesheet" type="text/css" />
<script src="/Scripts/jquery-1.5.1.min.js" type="text/javascript"></script>
<script src="/Scripts/modernizr-1.7.min.js" type="text/javascript"></script>
</head>
<body>
<img src="/2.jpg" alt="Big Pic" class="bg" />
<div class="top_40"></div>
<section id="main">
<script type="text/javascript">
$(document).ready(function () {
$('#close').click(function (event) {
closeAjax();
event.cancelBubble = true;
event.returnValue = false;
event.preventDefault();
event.stopPropagation();
});
});
$(document).ready(function () {
$("#index").validate({
rules: {
password: {
required: true, minlength: 6
},
c_password: {
required: true, equalTo: "#password", minlength: 6
}
},
messages: {
password: "Please enter your new password.",
c_password: "Please confirm your new password."
}
});
});
</script>
<div class="form_container">
<div class="logo">
<a href=""><img class="logo" src="/Content/SP_Logo_white.png" alt="Cloud"/></a>
</div>
<div class="reset">
<h3>Password Reset</h3>
<div class="reset-help">
<p>Forgot your password? Use the form to change or reset your password.</p>
</div>
<form action="/Reset/Reset?qString=qKkQBXYEsY0GthEqFIuWYfXQ1CKcUioxpbY8vfhqN9nlOcHrZdLIYzxxhtV0YK73" method="post"> <label for="reset">UserName:</label>
<input type="text" id="username" name="username" /><br />
<label for="password">New Password:</label>
<input type="password" id="password" name="password" /><br />
<label for="confirmpassword">Confirm Password:</label>
<input type="password" id="confirmpassword" name="confirmpassword" />
<p><input type="submit" id="submit" value="Submit" /></p>
</form> </div>
</div>
</section>
<div class="bottom_80"></div>
</body>
</html>