zoukankan      html  css  js  c++  java
  • jquery.form.js 异步提交表单

    Html

     <form id="insertForm" method="post" class="form-horizontal">
                            <div class="form-group" id="customerName">
                                <label class="col-sm-2 control-label"><font style='color:red;'>*</font>姓名</label>
                                <div class="col-sm-10"><input id="name" type="text" class="form-control" name="Name"></div>
                            </div>
                            <div class="hr-line-dashed"></div>
    
                            <div class="form-group">
                                <label class="col-sm-2 control-label"><font style='color:red;'>*</font>性别</label>
                                <div class="col-sm-10">
                                    <select id="sex" class="input-md form-control input-s-sm inline" name="Sex">
                                        <option value="true"></option>
                                        <option value="false"></option>
                                    </select>
                                </div>
                            </div>
                           
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">年龄</label>
                                <div class="col-sm-10"><input id="age" type="text" class="form-control" name="Age"></div>
                            </div>
    
                            <div class="hr-line-dashed"></div>
    
                            <div class="form-group">
                                <label class="col-sm-2 control-label">电话</label>
                                <div class="col-sm-10"><input id="tel" type="text" class="form-control" name="Tel"></div>
                            </div>
    
                        </form>

    JS

     var token = $("input[name = '__RequestVerificationToken']").val();  //防护CSRF
     $("#insertForm").ajaxSubmit({ url: "/Home/InsertInfo", type: 'post', dataType: 'json', data: { "__RequestVerificationToken": token   }, beforeSubmit: function () { alert("beforeSubmit") }, success: function (result) { alert("success") } });

    Entity

    public class User
        {
            public int ID { get; set; }
    
            public string Name { get; set; }
    
            public bool Sex { get; set; }
    
            public decimal Age { get; set; }
    
            public string Tel { get; set; }
    
            public DateTime? ModifyTime { get; set; }
    
    
    
        }

    Controll

     [ValidateAntiForgeryToken]
            public void InsertInfo(User user)
            {
                using (IDbConnection conn = DapperService.MySqlConnection())
                {
    
                }
            }

    截图

  • 相关阅读:
    c# 第29节 类
    c# 第28节 面向对象概述
    c# 第27节 结构、枚举
    c# 第26节 Main方法
    c# 第25节 方法重载
    Python接口自动化之yaml配置文件
    Python接口自动化之数据驱动
    Python接口自动化之登录接口测试
    测试面试题集-逻辑推理题
    Python接口自动化之unittest单元测试
  • 原文地址:https://www.cnblogs.com/xinyibufang/p/8665210.html
Copyright © 2011-2022 走看看