MVC注册
前言
最近没什么写的,写个MVC注册巩固一下
HTML
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>注册 - 瑰园美食</title>
<link rel="icon" href="~/Content/Images/Icon/Logo.png" />
<link href="~/Plugin/layui/css/layui.css" rel="stylesheet" />
<link href="~/Content/Css/LoginStyle.css" rel="stylesheet" />
</head>
<body>
<h1>
<span>瑰园美食</span>
<span>享受美食带来的欢乐~</span>
</h1>
<div class="LoginFrom">
<h2>注册</h2>
<div class="LoginFrom_Input">
<input spellcheck="false" class="Input_User" type="text" placeholder="账号" />
<input class="Input_Pass" type="password" placeholder="密码" />
<input class="SuccessButton" type="button" value="点我注册" />
<input onclick="window.location.href='/Main/Login'" type="button" value="已有账户?点击登录" />
</div>
</div>
<footer>
<p>©2019 Yolx</p>
</footer>
<script src="~/Plugin/layui/layui.all.js"></script>
<script>
var User = document.querySelectorAll(".Input_User")[0];
var Pass = document.querySelectorAll(".Input_Pass")[0];
var xhr1 = new XMLHttpRequest();
var SuccessButton = document.querySelectorAll(".SuccessButton")[0]
SuccessButton.onclick = function () {
if (User.value == "" || Pass.value == "") {
alert("请填写完整!")
} else {
xhr1.open("Get", "/Main/RegisterUser?User=" + User.value + "&Pass=" + Pass.value + "");
xhr1.responseType = "json";
xhr1.send();
xhr1.onreadystatechange = function () {
if (xhr1.status == 200 && xhr1.readyState == 4) {
if (xhr1.response.MsgState == true) {
alert(xhr1.response.MsgText);
window.location.href = "/Main/Login"
} else {
alert(xhr1.response.MsgText);
}
}
}
}
}
</script>
</body>
</html>
CSS
body {
margin: 0;
padding: 0;
background-image: url('../Images/LoginBG.jpg');
background-repeat: no-repeat;
background-size: 100%;
}
h1 {
position: fixed;
top: 50%;
left: 10%;
transform: translateY(-50%);
color: #fff;
}
h1 span {
display: block;
font-size: 3vh;
}
h1 span:nth-child(1) {
font-size: 5vh;
position: relative;
padding: 0.5vh 0px 1vh;
}
h1 span:nth-child(1):after {
content: '';
position: absolute;
left: 0;
top: 0;
width: 9.8vh;
height: 0.35vh;
background: #fff;
}
.LoginFrom {
width: 24vw;
height: 40vh;
position: fixed;
top: 50%;
right: 10%;
transform: translateY(-50%);
background: rgba(255, 255, 255, .8);
border-radius: 0.5vh;
overflow: hidden;
}
.LoginFrom h2 {
text-align: center;
padding: 2vh;
background: #fff;
font-size: 2vh;
}
.LoginFrom .LoginFrom_Input {
width: 100%;
padding: 2vh 0px;
}
.LoginFrom .LoginFrom_Input input {
border: 0;
width: 80%;
height: 5vh;
display: block;
padding: 0 1vh;
font-size: 2vh;
margin: 1vh auto;
box-sizing: content-box;
position: relative;
}
.ForgetPass, .RegisterUser {
font-size: 1vh !important;
position: absolute !important;
background: none;
width: auto !important;
height: auto !important;
bottom: 0px;
}
.SuccessButton {
background:#fff;
}
.SuccessButton:after {
content:'';
position:absolute;
left:0px;
bottom:0px;
height:2px;
width:10px;
background:#67b968;
}
/*.SuccessButton:hover {
border-bottom:1vh solid #67b968;
}*/
.ForgetPass {
left:0px;
}
.RegisterUser {
right:0px;
}
footer {
position: fixed;
bottom: 0px;
left: 0px;
width: 100%;
}
footer p {
text-align: center;
color: rgba(255, 255, 255, 0.8);
padding: 1.5vh 0px;
font-size: 1.5vh;
}
/*开关组*/
.OAO_YC {
width: 7vh;
height: 3vh;
background: #fff;
border-radius: 1vh;
padding: .5vh;
transition: all ease 0.5s;
position: relative;
overflow: hidden;
margin: 1vh 3.8vh;
}
.OAO_YC p {
position: absolute;
top: 0px;
left: 0px;
margin: 0;
padding: 0;
font-size: 1.5vh;
height: 100%;
width: 8vh;
text-align: center;
line-height: 2.7em;
opacity: 0;
transition: all ease 0.5s;
}
.OAO_YC:hover p {
opacity: 1;
}
.OAO_YC:hover span {
opacity: 0.3;
}
.OAO_YC span {
height: 100%;
background: #e47575;
border-radius: 1vh;
display: block;
width: 3.7vh;
transition: all ease 0.5s;
}
.OAO_YC_On {
transition: all ease 0.5s;
}
.OAO_YC_On span {
transform: translateX(3vh);
background: #67b968;
}
控制器
public ActionResult RegisterUser(string User, string Pass)
{
msg.MsgState = false;
var list = (from tbUser in MyModel.PW_User
where tbUser.UserName == User.Trim()
select tbUser).ToList();
if (list.Count == 0)
{
PW_User pW_User = new PW_User();
pW_User.UserName = User;
pW_User.UserPass = Pass;
MyModel.PW_User.Add(pW_User);
if (MyModel.SaveChanges() > 0)
{
msg.MsgState = true;
msg.MsgText = "注册成功";
return Json(msg, JsonRequestBehavior.AllowGet);
}
}
else
{
msg.MsgText = "已存在用户";
return Json(msg, JsonRequestBehavior.AllowGet);
}
msg.MsgText = "注册失败!";
return Json(msg, JsonRequestBehavior.AllowGet);
}
登录页面点击注册按钮跳转到注册页面
注册效果
后言
本文结束了,如果觉得本技术文章对你有帮助请给我点个赞,如果有什么不足的地方,给我提意见,让我加以改进