当服务器端发生错误时,如何调用Ajax.BeginForm的OnFailure事件?
我应该处理OnComplete函数的错误吗?
查看
<script type="text/javascript">
function PullIntoTable(e) {
・・・・・
}
function search_start() {
....
}
function Failure() {
alert("Called!!");
}
.........
</script>
@using (Ajax.BeginForm("Search", "SearchCompanyJP",
new AjaxOptions { HttpMethod = "POST", OnBegin = "search_start", OnSuccess = "PullIntoTable", OnFailure = "Failure", OnComplete = "search_close" }))
{
<div>
<span class="label">Company</span>
@Html.TextBoxFor(m => m.CompanyName, new { @class = "textbox" })
</div>
<div>
<span class="label">Address</span>
@Html.TextBoxFor(m => m.Address, new { @class = "textbox" })
</div>
<input type="submit" value="Search" />
}
XXXService.cs - 由控制器调用
Insertable = false;
if (Insertable)
{
・・・・・
}
else
{
throw new CustomException(action, message);
}
Global.asax ---由于ajax,此重定向不起作用。这就是我实现失败功能的原因。
void Application_Error(Object sender, EventArgs e)
{
var exception = Server.GetLastError();
Server.ClearError();
Response.Redirect("/Error", false);
}