码迷,mamicode.com
首页 > Web开发 > 详细

jquery.form.js 异步提交表单

时间:2018-03-28 18:56:13      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:分享   validate   odi   url   input   home   blog   ica   connect   

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

            }
        }

 

截图

技术分享图片技术分享图片技术分享图片

 

jquery.form.js 异步提交表单

标签:分享   validate   odi   url   input   home   blog   ica   connect   

原文地址:https://www.cnblogs.com/xinyibufang/p/8665210.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!