blockUI error "Object doesn't support this property or method"
I'm running this from within VS2010 and an error comes up when the form is submitted which says "Microsoft JScrip开发者_如何学运维t runtime error: Object doesn't support this property or method". Any suggestions?
<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 = ""
}))
You should change
OnBegin = "BlockUI()",
to
OnBegin = "BlockUI"
According to MSDN OnBegin
takes:
The name of the JavaScript function to call before the page is updated.
The additional ()
probably makes the underlying JavaScript execute the function immediately, causing the error.
Similarly, with OnFailure
:
OnFailure = "function() { alert('Failed to update switch'); }",
Also, you don't need to specify property values of AjaxOptions
that you aren't using:
@using (Ajax.BeginForm("Switch", new AjaxOptions() {
UpdateTargetId = "Switch" + Model.Id,
InsertionMode = InsertionMode.Replace,
OnBegin = "BlockUI",
OnFailure = "function() { alert('Failed to update switch'); }",
HttpMethod = "POST"
}))
精彩评论