0

我在 VS2010 中运行它,提交表单时出现错误,显示“Microsoft JScript 运行时错误:对象不支持此属性或方法”。有什么建议么?

<script type="text/javascript">
function BlockUI() {
    $.blockUI({ message: "<h1>Remote call in progress...</h1>" });
}
</script>

@using (Ajax.BeginForm("Switch", new AjaxOptions()  {
        UpdateTargetId = "Switch" + Model.Id, 
        InsertionMode = InsertionMode.Replace,
        OnSuccess = "",
        OnBegin = "BlockUI()",
        OnComplete = "",
        OnFailure = "alert('Failed to update switch')",
        Confirm = "",
        HttpMethod = "POST",
        LoadingElementId = "",
        Url = ""
    }))
4

1 回答 1

1

你应该改变

OnBegin = "BlockUI()",

OnBegin = "BlockUI"

根据 MSDN OnBegin需要:

在页面更新之前要调用的 JavaScript 函数的名称。

附加()可能会使底层 JavaScript 立即执行该函数,从而导致错误。

同样,与OnFailure

OnFailure = "function() { alert('Failed to update switch'); }",

此外,您不需要指定AjaxOptions不使用的属性值:

@using (Ajax.BeginForm("Switch", new AjaxOptions()  {
        UpdateTargetId = "Switch" + Model.Id, 
        InsertionMode = InsertionMode.Replace,
        OnBegin = "BlockUI",
        OnFailure = "function() { alert('Failed to update switch'); }",
        HttpMethod = "POST"
    }))
于 2011-03-08T01:28:34.617 回答