Login页面前端代码
div>
<form action="/First/Login" method="post">
账号<input type="text" name="zhanghao"/><br />
密码<input type="text" name="mima"/><br />
<input type="submit" value="登录"/><br />
</form>
</div>
后台代码
1) 首先要在model层 创建EF框架(访问数据库比较方便)
再model层写一个类,用于访问类
public class UserSever
{
public static Sysuser Login(string id,string mima) {
using (fashionshoppingDBEntities db=new fashionshoppingDBEntities())
{
Sysuser sysuser=db.Sysuser.FirstOrDefault(s => s.username == id && s.pwd == mima);
return sysuser;
}
}
}
2)Login页面(action)的后台代码
public ActionResult Login()
{
return View();
}
[HttpPost]
public ActionResult Login(string zhanghao,string mima) {
Sysuser sysuser = UserSever.Login(zhanghao, mima);
if (sysuser!=null)
{
return RedirectToAction("About");
}
else
{
return Content("<script>alert('账号或者密码不正确');window.location.href='../First/Login';</script>");
}
}
public ActionResult About() {
return View();
}
}
请发表评论