一、控制器代码
public ActionResult login()
{
return View();
}
[HttpPost]
public ActionResult login(string UserName,string Pwd)
{
using (ChangeDBEntities db = new ChangeDBEntities())
{
var list=db.Users.FirstOrDefault(p=>p.UserName==UserName&&p.Pwd==Pwd);
if(list != null)
{
return Content("<script>alert('登录成功');location.href='/Show/Index'</script>");
}
else
{
return Content("<script>alert('请重新输入用户名和密码');location.href='/Show/login'</script>");
}
}
}
二、视图代码
@{
Layout = null;
}
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Change官网</title>
<link href="/Content2/css/global.css" rel="stylesheet" type="text/css">
<link href="/Content2/css/Site.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="all">
<!--头部-->
<div id="head">
<ul>
<li id="headone"><a href="Index.html"> <img src="/Content2/images/logo/logo.png" alt="Change官网" /></a></li>
<li id="headtwo"><a href="Index.html">☞Change商城</a>|<a href="/Show/login">登录</a> |<a href="/Show/register">注册</a></li>
<div class="clear"></div>
</ul>
</div>
<!--登录窗体-->
<div id="middle">
<div id="login">
<h2>用户登录</h2>
<hr />
<form action="/Show/login" method="post">
<input type="text" name="UserName" class="text" placeholder="用户名" />
<input type="password" name="Pwd" class="text" placeholder="密码" />
<input type="submit" class="btn" value="登 录" />
</form>
</div>
</div>
<!--尾部-->
<div id="foots">
<!--
<div id="server">
<div id="serverone">
<ul>
<li><img src="images/ico/2_03.gif"></li>
<li><img src="images/ico/2_04.gif"></li>
<li><img src="images/ico/2_05.gif"></li>
<li><img src="images/ico/2_06.gif"></li>
<li><img src="images/ico/2_07.gif"></li>
<div class="clear"></div>
</ul>
</div>
-->
<div id="copy"> <p>©2016 Change Technology official website retains all rights.鄂ICP备16001830号</p></div>
</div>
</div>
</body>
</html>