标签:
在根据网上的方法进行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); }
标签:
原文地址:http://www.cnblogs.com/cloud-shadow/p/5646439.html