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())
                {
    
                }
            }

    截图

  • 相关阅读:
    Idea debug报错Command line is too long
    云计算与虚拟化入门通识
    yield from语法
    python中 os._exit() 和 sys.exit(), exit(0)和exit(1) 的用法和区别
    python模块中sys.argv[]使用
    SQLAlchemy中Model.query和session.query(Model)的区别
    MAN VGEXTEND
    Python---基础---dict和set
    Python---基础---元组
    Python---基础---list(列表)
  • 原文地址:https://www.cnblogs.com/xinyibufang/p/8665210.html
Copyright © 2011-2022 走看看