mvc4 ajax 提交form

在根据网上的方法进行mvc ajax 提交form时成功后总是会跳转至一个空白界面并仅显示返回的数据,之后又经过多次查找资料找到了解决方法,具体用法如下(注意红色字体)

<head>
    <script type="text/javascript" src="@Url.Content("~/scripts/jquery.form.min.js")"></script>
    <meta name="viewport" content="width=device-width" />
    <title>新增信息</title>
    <script type="text/javascript">
        $(function(){ 
            var options = {  
                url:"/Info/Info_Add",
                beforeSubmit:  showRequest,  //提交前处理 
                success:       showResponse,  //处理完成 
                resetForm: false 
            };  
  
            $('#info_form').submit(function() {  
                $(this).ajaxSubmit(options);  
            }).submit(function(){return false;});  
        }); 
 
        function showRequest(formData, jqForm, options) {  
            alert("提请前");
            return true;  
        }  
  
        function showResponse(data)  {  
            if(data=="1")
            {
                alert("修改成功!");
            }
        } 
    </script>

</head>
<body>
<form id="info_form" name="info_form" action="/Info/Info_Add" method="post">
                <table class="pure-table pure-table-horizontal">
                    <tr>
                        <td style="width: auto">案件编号:</td>
                        <td style="width: auto">@Html.TextBox("caseid", cid, new { disabled = "disabled", @readonly = "readonly" })</td>
                    </tr>
<tr>                        <td style="width: auto" align="center" colspan="2">

                            <input type="button" id="tolist" name="tolist" class="btn" value="查看已发布清单"  style="display:none" onclick="location.href='@Url.Action("NewsList", "News")    '"  />

                            <input type="submit" value="添加" />
                        </td>
                    </tr>
                </table>
            </form>
</body>

control:

  [HttpPost]
        public ActionResult Info_Add(string id)
        {
            string s1=Request.Form["caseCusname"];
            string rs = "1";
            return Content(rs);
        }

 

转载于:https://www.cnblogs.com/cloud-shadow/p/5646439.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值