MVC 会员注册

时间:2023-03-10 04:58:41
MVC 会员注册
 @{
ViewBag.Title = "Register";
} <script src="~/Scripts/jquery-2.1.0.js"></script>
<script src="~/Scripts/jquery.validate.js"></script>
<script src="~/Scripts/jqury.common.js"></script>
<script type="text/javascript">
jQuery(document).ready(function () {
jQuery("#Registerform").validate({
rules: {
Account: "required",
Password: "required",
ConfirmPassword: {
required: true,
equalTo:"#Password"
},
Email: {
required: true,
email:true
}
},
messages: {
Account: "输入账号!",
Password: "输入密码!",
ConfirmPassword: {
required:"输入确认密码!",
equalTo:"输入相同的密码!"
},
Email: {
required: "输入邮箱地址!",
email:"不是有效的邮箱地址!"
}
}
}) jQuery("#btnReg").click(function () {
if (jQuery("#Registerform").valid()) {
jQuery.ajax({
type: "Post",
url: "/Member/Register",
dataType: "json",
data: JSON.stringify({
Account: jQuery("#Account").val(),
Password: jQuery("#Password").val(),
Email: jQuery("#Email").val()
}),
contentType: "application/json;charset=utf-8",
success: function (result) {
window.alert("注册成功!");
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
//window.alert(errorThrown);
jQuery.AlertException(XMLHttpRequest,errorThrown);
}
})
}
else {
return;
}
})
})
</script>
@using (Html.BeginForm(null, null, FormMethod.Post, new { id = "Registerform" }))
{
<span>Account</span> <input type="text" id="Account" name="Account" /><br />
<span>Password</span><input type="password" id="Password" name="Password" /><br />
<span>Confirm Password</span><input type="password" id="ConfirmPassword" name="ConfirmPassword" /><br />
<span>Email</span><input type="text" id="Email" name="Email" /><br />
<input type="button" id="btnReg" value="注册" />
}
 MemberEntity objMemberEntity = new MemberEntity();
public ActionResult Register()
{
return View();
}
[HttpPost]
public ActionResult Register(Member member)
{
objMemberEntity.Register(member);
return Json(member,JsonRequestBehavior.AllowGet);
} public int Register(Member member)
{
SqlParameter[] sqlpar = {
new SqlParameter("@Account",member.Account),
new SqlParameter("@Password",member.Password),
new SqlParameter("@Email",member.Email)
}; return SQLHelper.ExecuteCommand("usp_Member_Register", CommandType.StoredProcedure, sqlpar);
}