zoukankan      html  css  js  c++  java
  • mvc自带的异步表单提交

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Web;
     5 using System.Web.Mvc;
     6 
     7 namespace MvcValidateDemo.Controllers
     8 {
     9     public class AjaxController : Controller
    10     {
    11         //
    12         // GET: /Ajax/
    13 
    14         public ActionResult Index()
    15         {
    16             return View();
    17         }
    18 
    19         public ActionResult GetDate()
    20         {
    21             //让网站睡眠1秒钟
    22             System.Threading.Thread.Sleep(1000);
    23             return Content(DateTime.Now.ToString());
    24         }
    25 
    26         public ActionResult MicrosoftAjax()
    27         {
    28             return View();
    29         }
    30 
    31     }
    32 }
     1 @{
     2     Layout = null;
     3 }
     4 
     5 <!DOCTYPE html>
     6 
     7 <html>
     8 <head>
     9     <meta name="viewport" content="width=device-width" />
    10     <title>MicrosoftAjax</title>
    11     <script src="~/Scripts/jquery-1.8.2.js"></script>
    12     <script src="~/Scripts/jquery.unobtrusive-ajax.js"></script>
    13     <script type="text/javascript">
    14         function afterSuccess(data) {
    15             //alert(data);
    16         }
    17     </script>
    18 </head>
    19 <body>
    20     <div>
    21         @using (Ajax.BeginForm("GetDate", "Ajax", new AjaxOptions(){Confirm  ="您是否要提交吗?",HttpMethod = "Post",InsertionMode = InsertionMode.InsertAfter,UpdateTargetId = "result",OnSuccess="afterSuccess",LoadingElementId = "loading"}))
    22         {
    23             <div>
    24                 用户名:<input type="text" name="UserName" /><br />
    25                 密码:<input type="text" name="Pwd"/><br />
    26                 <input type="submit" value="提交"/>
    27             </div>
    28         }
    29         
    30         <div id="result">
    31 
    32         </div>
    33         
    34         <div id="loading" style="display:none">
    35             <img src="~/Content/ico_loading2.gif" />
    36         </div>
    37     </div>
    38 </body>
    39 </html>
  • 相关阅读:
    PHP 反射API
    wamp下mysql错误提示乱码的解法
    PDO、PDOStatement、PDOException
    PHP 常用函数
    TCP/IP
    centOS7+mariadb+Nginx+PHP7.0 安装
    php中引用&的真正理解-变量引用、函数引用、对象引用
    cgi fastcgi php-cgi php-fpm
    03 : linux判断服务器是虚拟机还是物理机
    02 :history命令显示日期-时间-登录IP-用户名
  • 原文地址:https://www.cnblogs.com/qinsilandiao/p/4967043.html
Copyright © 2011-2022 走看看