我用mvc做数据校验的时候,不管Controller返回“ok”还是view视图,都会被Ajax.BeginForm视为操作正确,执行OnSuccess = "afterEdit"函数,就出不来校验结果了。
设置一个viewData[]或ViewBag再在cshtml中检查
能具体点吗?谢谢
@Invictus:
1、ViewData["ListSyncTimePeriod"]在你的action里面设置
2、@using (Html.BeginForm("AddWhiteChannel", "WhiteChannel", FormMethod.Post))
{
string ListSyncTimePeriod = ViewData["ListSyncTimePeriod"].ToString();
……// 根据返回值做检查
}
@滴答的雨: 怎么通过ListSyncTimePeriod的不同值触发OnSuccess或OnFailure函数?
@Invictus:
再ajax调用一次后台?
$.ajax({ type: "POST", url: "/ChannelMgr/WhiteChannel/DeleteWhiteChannel", data: { checkId: checkId.join(',') }, dataType: "json", success: function (data) { if (data == true) { Dialog.alert("删除成功!大约在" + "@ListSyncTimePeriod" + "分钟后生效。"); } var params; params = { extParam: { "Phone": phone, "name": name } }; var grid = $("#grid")[0]; if (grid.rows.length == checkId.length) { //if(grid.p.total>1) grid[0].p.newp = grid.p.total - 1; //翻到上一页 grid.p.newp = 1; } $('#grid').flexOptions(params).flexReload(); } });
<script type="text/javascript"> function afterEdit() { debugger; } </script> @{ Html.EnableClientValidation(); } @using (Ajax.BeginForm("AjaxForm", "Common", new AjaxOptions { HttpMethod = "POST", OnBegin = "function(){ loadingPanel.Show(); }", OnComplete = "function(){ loadingPanel.Hide(); }", OnSuccess = "function(){afterEdit();}", },
我这样测试是可以的
http://www.cnblogs.com/aehyok/archive/2013/03/30/2989393.html可以看一下这篇文章,可能是你少引用了一个JavaScript文件。