MVC 提交表单

 

技术分享
 1  public ActionResult UserLogin()
 2         {
 3             var UserName = Request["username"];
 4             var Password = Request["password"];
 5             
 6             if (UserName =="admin")
 7             {
 8                 if (Password=="admin")
 9                 {
10                     return Content("ok:登录成功!!!");
11                 }
12                 else
13                 {
14                     return Content("no:密码输入错误!!!");
15 
16                 }
17             }
18             else
19             {
20                 return Content("no:账户输入错误,请重新输入!!!");
21             }
22         }
View Code
 1 @{
 2     Layout = null;
 3 }
 4 
 5 <!DOCTYPE html>
 6 
 7 <html>
 8 <head>
 9     <meta name="viewport" content="width=device-width" />
10     <script src="~/Scripts/jquery-1.8.2.min.js"></script>
11     <script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
12     <title>登录</title>
13     <script type="text/javascript">
14         function afterLogin(data) {//提交成功后回调
15             var serverData = data.split(:);
16             if (serverData[0] == "ok") {
17                 window.location.href = "/Main/Index";
18             }
19             else if (serverData[0] == "no") {
20                 $("#error").text(serverData[1]);
21             }
22             else {
23                 $("#error").text("系统繁忙!!");
24             }
25         }
26     </script>
27    
28 </head>
29 <body>
30     <div class="logindiv">
31         @using (Ajax.BeginForm("UserLogin", new { }, new AjaxOptions() { HttpMethod = "post", OnSuccess = "afterLogin" }, new { id = "loginForm" }))
32         {
33             <div class="hide"></div>
34             <table class="logintab">
35                 <tbody>
36                     <tr>
37                         <td colspan="2" align="left">
38                             <h3>请使用用户名或工号登录!!!</h3>
39                         </td>
40                     </tr>
41                     <tr>
42                         <td colspan="2">
43                             <div class="hide"></div>
44                         </td>
45                     </tr>
46                     <tr>
47                         <td align="right">账户:</td>
48                         <td align="left">
49                             <input type="text" name="username" class="ipt" /></td>
50                     </tr>
51                     <tr>
52                         <td align="right">密码:</td>
53                         <td align="left">
54                             <input type="password" name="password" class="ipt" /></td>
55                     </tr>
56                     <tr>
57                         <td colspan="2" align="right">
58                             <input type="submit" value="登录" class="sub" />
59                         </td>
60                     </tr>
61                     <tr>
62                         <td colspan="2"><span class="sperror" id="error"></span></td>
63                     </tr>
64                 </tbody>
65             </table>
66         }
67     </div>
68 </body>
69 </html>

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。