MVC 提交表单

  public ActionResult UserLogin()
{
var UserName = Request["username"];
var Password = Request["password"]; if (UserName =="admin")
{
if (Password=="admin")
{
return Content("ok:登录成功!!!");
}
else
{
return Content("no:密码输入错误!!!"); }
}
else
{
return Content("no:账户输入错误,请重新输入!!!");
}
}
 @{
Layout = null;
} <!DOCTYPE html> <html>
<head>
<meta name="viewport" content="width=device-width" />
<script src="~/Scripts/jquery-1.8.2.min.js"></script>
<script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
<title>登录</title>
<script type="text/javascript">
function afterLogin(data) {//提交成功后回调
var serverData = data.split(':');
if (serverData[0] == "ok") {
window.location.href = "/Main/Index";
}
else if (serverData[0] == "no") {
$("#error").text(serverData[1]);
}
else {
$("#error").text("系统繁忙!!");
}
}
</script> </head>
<body>
<div class="logindiv">
@using (Ajax.BeginForm("UserLogin", new { }, new AjaxOptions() { HttpMethod = "post", OnSuccess = "afterLogin" }, new { id = "loginForm" }))
{
<div class="hide"></div>
<table class="logintab">
<tbody>
<tr>
<td colspan="2" align="left">
<h3>请使用用户名或工号登录!!!</h3>
</td>
</tr>
<tr>
<td colspan="2">
<div class="hide"></div>
</td>
</tr>
<tr>
<td align="right">账户:</td>
<td align="left">
<input type="text" name="username" class="ipt" /></td>
</tr>
<tr>
<td align="right">密码:</td>
<td align="left">
<input type="password" name="password" class="ipt" /></td>
</tr>
<tr>
<td colspan="2" align="right">
<input type="submit" value="登录" class="sub" />
</td>
</tr>
<tr>
<td colspan="2"><span class="sperror" id="error"></span></td>
</tr>
</tbody>
</table>
}
</div>
</body>
</html>
上一篇:C#中string类型是值类型还是引用类型?


下一篇:JAVA程序员常用开发工具