Microsoft.JSInterop.JSException:当前没有元素与组件关联

Posted

技术标签:

【中文标题】Microsoft.JSInterop.JSException:当前没有元素与组件关联【英文标题】:Microsoft.JSInterop.JSException: No element is currently associated with component 【发布时间】:2021-04-14 19:30:58 【问题描述】:

我正在使用 .NET 5.0.101、ASP.NET Core 5 Blazor WebAssembly、Google Chrome、Windows 10 x64 版本 2004、Visual Studio 2019。

async void DeleteWithConfirmation(int id)

    //delete
    bool isConfirmed = await JsRuntime.InvokeAsync<bool>("confirm(\"Bạn có chắc chắn muốn xóa ?\")");
    if (isConfirmed)
    
        await Http.DeleteAsync("SAQuote/" + id);
        await Grid.Refresh();
    

错误

 617
Error: No element is currently associated with component 617
    at e.updateComponent (https://localhost:5001/_framework/blazor.webassembly.js:1:31696)
    at Object.t.renderBatch (https://localhost:5001/_framework/blazor.webassembly.js:1:12129)
    at Object.window.Blazor._internal.renderBatch (https://localhost:5001/_framework/blazor.webassembly.js:1:61899)
    at Object.w [as invokeJSFromDotNet] (https://localhost:5001/_framework/blazor.webassembly.js:1:64421)
    at _mono_wasm_invoke_js_blazor (https://localhost:5001/_framework/dotnet.5.0.1.js:1:190800)
    at wasm_invoke_iiiiii (<anonymous>:wasm-function[5611]:0xdda7f)
    at ves_pinvoke_method (<anonymous>:wasm-function[5708]:0xdfb62)
    at interp_exec_method (<anonymous>:wasm-function[2155]:0x44c08)
    at interp_runtime_invoke (<anonymous>:wasm-function[7862]:0x12efff)
    at mono_jit_runtime_invoke (<anonymous>:wasm-function[7347]:0x118e5f)
   at Microsoft.JSInterop.WebAssembly.WebAssemblyJSRuntime.InvokeUnmarshalled[Int32,RenderBatch,Object,Object](String identifier, Int32 arg0, RenderBatch arg1, Object arg2, Int64 targetInstanceId)
   at Microsoft.JSInterop.WebAssembly.WebAssemblyJSRuntime.InvokeUnmarshalled[Int32,RenderBatch,Object](String identifier, Int32 arg0, RenderBatch arg1)
   at Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer.UpdateDisplayAsync(RenderBatch& batch)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue()
d.printErr @ blazor.webassembly.js:1
d.preRun.push.window.Blazor._internal.dotNetCriticalError @ blazor.webassembly.js:1
w @ blazor.webassembly.js:1
_mono_wasm_invoke_js_blazor @ dotnet.5.0.1.js:1
do_icall @ 00aba26a:0x194e58
do_icall_wrapper @ 00aba26a:0x79df9
interp_exec_method @ 00aba26a:0x44ad3
interp_runtime_invoke @ 00aba26a:0x12efff
mono_jit_runtime_invoke @ 00aba26a:0x118e5f
do_runtime_invoke @ 00aba26a:0x79d42
mono_runtime_try_invoke @ 00aba26a:0x12982
mono_set_timeout_exec @ 00aba26a:0x10e1e6
Module._mono_set_timeout_exec @ dotnet.5.0.1.js:1
(anonymous) @ dotnet.5.0.1.js:1
setTimeout (async)
_mono_set_timeout @ dotnet.5.0.1.js:1
mono_wasm_set_timeout @ 00aba26a:0x1089e2
do_icall @ 00aba26a:0x194d11
do_icall_wrapper @ 00aba26a:0x79df9
interp_exec_method @ 00aba26a:0x44ad3
interp_runtime_invoke @ 00aba26a:0x12efff
mono_jit_runtime_invoke @ 00aba26a:0x118e5f
do_runtime_invoke @ 00aba26a:0x79d42
mono_runtime_try_invoke @ 00aba26a:0x12982
mono_runtime_invoke @ 00aba26a:0x10ec2b
mono_wasm_invoke_method @ 00aba26a:0x108e48
Module._mono_wasm_invoke_method @ dotnet.5.0.1.js:1
call_method @ dotnet.5.0.1.js:1
set_task_result @ dotnet.5.0.1.js:1
(anonymous) @ dotnet.5.0.1.js:1
Promise.then (async)
js_to_mono_obj @ dotnet.5.0.1.js:1
mono_wasm_convert_return_value @ dotnet.5.0.1.js:1
_mono_wasm_invoke_js_with_args @ dotnet.5.0.1.js:1
do_icall @ 00aba26a:0x194de5
do_icall_wrapper @ 00aba26a:0x79df9
interp_exec_method @ 00aba26a:0x44ad3
interp_runtime_invoke @ 00aba26a:0x12efff
mono_jit_runtime_invoke @ 00aba26a:0x118e5f
do_runtime_invoke @ 00aba26a:0x79d42
mono_runtime_try_invoke @ 00aba26a:0x12982
mono_runtime_invoke @ 00aba26a:0x10ec2b
mono_wasm_invoke_method @ 00aba26a:0x108e48
Module._mono_wasm_invoke_method @ dotnet.5.0.1.js:1
call_method @ dotnet.5.0.1.js:1
set_task_result @ dotnet.5.0.1.js:1
(anonymous) @ dotnet.5.0.1.js:1
Promise.then (async)
js_to_mono_obj @ dotnet.5.0.1.js:1
mono_wasm_convert_return_value @ dotnet.5.0.1.js:1
_mono_wasm_invoke_js_with_args @ dotnet.5.0.1.js:1
do_icall @ 00aba26a:0x194de5
do_icall_wrapper @ 00aba26a:0x79df9
interp_exec_method @ 00aba26a:0x44ad3
interp_runtime_invoke @ 00aba26a:0x12efff
mono_jit_runtime_invoke @ 00aba26a:0x118e5f
do_runtime_invoke @ 00aba26a:0x79d42
mono_runtime_try_invoke @ 00aba26a:0x12982
mono_runtime_invoke @ 00aba26a:0x10ec2b
mono_wasm_invoke_method @ 00aba26a:0x108e48
Module._mono_wasm_invoke_method @ dotnet.5.0.1.js:1
call_method @ dotnet.5.0.1.js:1
(anonymous) @ dotnet.5.0.1.js:1
endInvokeJSFromDotNet @ blazor.webassembly.js:1
(anonymous) @ blazor.webassembly.js:1
Promise.then (async)
beginInvokeJSFromDotNet @ blazor.webassembly.js:1
w @ blazor.webassembly.js:1
_mono_wasm_invoke_js_blazor @ dotnet.5.0.1.js:1
do_icall @ 00aba26a:0x194e58
do_icall_wrapper @ 00aba26a:0x79df9
interp_exec_method @ 00aba26a:0x44ad3
interp_runtime_invoke @ 00aba26a:0x12efff
mono_jit_runtime_invoke @ 00aba26a:0x118e5f
do_runtime_invoke @ 00aba26a:0x79d42
mono_runtime_try_invoke @ 00aba26a:0x12982
mono_runtime_invoke @ 00aba26a:0x10ec2b
mono_wasm_invoke_method @ 00aba26a:0x108e48
Module._mono_wasm_invoke_method @ dotnet.5.0.1.js:1
call_method @ dotnet.5.0.1.js:1
(anonymous) @ dotnet.5.0.1.js:1
endInvokeJSFromDotNet @ blazor.webassembly.js:1
(anonymous) @ blazor.webassembly.js:1
Promise.then (async)
beginInvokeJSFromDotNet @ blazor.webassembly.js:1
w @ blazor.webassembly.js:1
_mono_wasm_invoke_js_blazor @ dotnet.5.0.1.js:1
do_icall @ 00aba26a:0x194e58
do_icall_wrapper @ 00aba26a:0x79df9
interp_exec_method @ 00aba26a:0x44ad3
interp_runtime_invoke @ 00aba26a:0x12efff
mono_jit_runtime_invoke @ 00aba26a:0x118e5f
do_runtime_invoke @ 00aba26a:0x79d42
mono_runtime_invoke_checked @ 00aba26a:0xf65d
mono_runtime_try_invoke_array @ 00aba26a:0x10e831
ves_icall_InternalInvoke @ 00aba26a:0xed492
ves_icall_InternalInvoke_raw @ 00aba26a:0xecf57
do_icall @ 00aba26a:0x194de5
do_icall_wrapper @ 00aba26a:0x79df9
interp_exec_method @ 00aba26a:0x44ad3
interp_runtime_invoke @ 00aba26a:0x12efff
mono_jit_runtime_invoke @ 00aba26a:0x118e5f
do_runtime_invoke @ 00aba26a:0x79d42
mono_runtime_try_invoke @ 00aba26a:0x12982
mono_runtime_invoke @ 00aba26a:0x10ec2b
mono_wasm_invoke_method @ 00aba26a:0x108e48
Module._mono_wasm_invoke_method @ dotnet.5.0.1.js:1
call_method @ dotnet.5.0.1.js:1
(anonymous) @ dotnet.5.0.1.js:1
beginInvokeDotNetFromJS @ blazor.webassembly.js:1
h @ blazor.webassembly.js:1
e.invokeMethodAsync @ blazor.webassembly.js:1
(anonymous) @ blazor.webassembly.js:1
(anonymous) @ blazor.webassembly.js:1
(anonymous) @ blazor.webassembly.js:1
(anonymous) @ blazor.webassembly.js:1
r @ blazor.webassembly.js:1
(anonymous) @ blazor.webassembly.js:1
(anonymous) @ blazor.webassembly.js:1
(anonymous) @ blazor.webassembly.js:1
(anonymous) @ blazor.webassembly.js:1
(anonymous) @ blazor.webassembly.js:1
r @ blazor.webassembly.js:1
d @ blazor.webassembly.js:1
f @ blazor.webassembly.js:1
(anonymous) @ blazor.webassembly.js:1
(anonymous) @ blazor.webassembly.js:1
e.onGlobalEvent @ blazor.webassembly.js:1
Show 44 more frames
blazor.webassembly.js:1 crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: No element is currently associated with component 530
      Error: No element is currently associated with component 530
          at e.updateComponent (https://localhost:5001/_framework/blazor.webassembly.js:1:31696)
          at Object.t.renderBatch (https://localhost:5001/_framework/blazor.webassembly.js:1:12129)
          at Object.window.Blazor._internal.renderBatch (https://localhost:5001/_framework/blazor.webassembly.js:1:61899)
          at Object.w [as invokeJSFromDotNet] (https://localhost:5001/_framework/blazor.webassembly.js:1:64421)
          at _mono_wasm_invoke_js_blazor (https://localhost:5001/_framework/dotnet.5.0.1.js:1:190800)
          at wasm_invoke_iiiiii (<anonymous>:wasm-function[5611]:0xdda7f)
          at ves_pinvoke_method (<anonymous>:wasm-function[5708]:0xdfb62)
          at interp_exec_method (<anonymous>:wasm-function[2155]:0x44c08)
          at interp_runtime_invoke (<anonymous>:wasm-function[7862]:0x12efff)
          at mono_jit_runtime_invoke (<anonymous>:wasm-function[7347]:0x118e5f)
Microsoft.JSInterop.JSException: No element is currently associated with component 530
Error: No element is currently associated with component 530
    at e.updateComponent (https://localhost:5001/_framework/blazor.webassembly.js:1:31696)
    at Object.t.renderBatch (https://localhost:5001/_framework/blazor.webassembly.js:1:12129)
    at Object.window.Blazor._internal.renderBatch (https://localhost:5001/_framework/blazor.webassembly.js:1:61899)
    at Object.w [as invokeJSFromDotNet] (https://localhost:5001/_framework/blazor.webassembly.js:1:64421)
    at _mono_wasm_invoke_js_blazor (https://localhost:5001/_framework/dotnet.5.0.1.js:1:190800)
    at wasm_invoke_iiiiii (<anonymous>:wasm-function[5611]:0xdda7f)
    at ves_pinvoke_method (<anonymous>:wasm-function[5708]:0xdfb62)
    at interp_exec_method (<anonymous>:wasm-function[2155]:0x44c08)
    at interp_runtime_invoke (<anonymous>:wasm-function[7862]:0x12efff)
    at mono_jit_runtime_invoke (<anonymous>:wasm-function[7347]:0x118e5f)
   at Microsoft.JSInterop.WebAssembly.WebAssemblyJSRuntime.InvokeUnmarshalled[Int32,RenderBatch,Object,Object](String identifier, Int32 arg0, RenderBatch arg1, Object arg2, Int64 targetInstanceId)
   at Microsoft.JSInterop.WebAssembly.WebAssemblyJSRuntime.InvokeUnmarshalled[Int32,RenderBatch,Object](String identifier, Int32 arg0, RenderBatch arg1)
   at Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer.UpdateDisplayAsync(RenderBatch& batch)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue()
d.printErr @ blazor.webassembly.js:1
d.preRun.push.window.Blazor._internal.dotNetCriticalError @ blazor.webassembly.js:1
w @ blazor.webassembly.js:1
_mono_wasm_invoke_js_blazor @ dotnet.5.0.1.js:1
do_icall @ 00aba26a:0x194e58
do_icall_wrapper @ 00aba26a:0x79df9
interp_exec_method @ 00aba26a:0x44ad3
interp_runtime_invoke @ 00aba26a:0x12efff
mono_jit_runtime_invoke @ 00aba26a:0x118e5f
do_runtime_invoke @ 00aba26a:0x79d42
mono_runtime_try_invoke @ 00aba26a:0x12982
mono_set_timeout_exec @ 00aba26a:0x10e1e6
Module._mono_set_timeout_exec @ dotnet.5.0.1.js:1
(anonymous) @ dotnet.5.0.1.js:1
setTimeout (async)
_mono_set_timeout @ dotnet.5.0.1.js:1
mono_wasm_set_timeout @ 00aba26a:0x1089e2
do_icall @ 00aba26a:0x194d11
do_icall_wrapper @ 00aba26a:0x79df9
interp_exec_method @ 00aba26a:0x44ad3
interp_runtime_invoke @ 00aba26a:0x12efff
mono_jit_runtime_invoke @ 00aba26a:0x118e5f
do_runtime_invoke @ 00aba26a:0x79d42
mono_runtime_try_invoke @ 00aba26a:0x12982
mono_runtime_invoke @ 00aba26a:0x10ec2b
mono_wasm_invoke_method @ 00aba26a:0x108e48
Module._mono_wasm_invoke_method @ dotnet.5.0.1.js:1
call_method @ dotnet.5.0.1.js:1
set_task_result @ dotnet.5.0.1.js:1
(anonymous) @ dotnet.5.0.1.js:1
Promise.then (async)
js_to_mono_obj @ dotnet.5.0.1.js:1
mono_wasm_convert_return_value @ dotnet.5.0.1.js:1
_mono_wasm_invoke_js_with_args @ dotnet.5.0.1.js:1
do_icall @ 00aba26a:0x194de5
do_icall_wrapper @ 00aba26a:0x79df9
interp_exec_method @ 00aba26a:0x44ad3
interp_runtime_invoke @ 00aba26a:0x12efff
mono_jit_runtime_invoke @ 00aba26a:0x118e5f
do_runtime_invoke @ 00aba26a:0x79d42
mono_runtime_try_invoke @ 00aba26a:0x12982
mono_runtime_invoke @ 00aba26a:0x10ec2b
mono_wasm_invoke_method @ 00aba26a:0x108e48
Module._mono_wasm_invoke_method @ dotnet.5.0.1.js:1
call_method @ dotnet.5.0.1.js:1
set_task_result @ dotnet.5.0.1.js:1
(anonymous) @ dotnet.5.0.1.js:1
Promise.then (async)
js_to_mono_obj @ dotnet.5.0.1.js:1
mono_wasm_convert_return_value @ dotnet.5.0.1.js:1
_mono_wasm_invoke_js_with_args @ dotnet.5.0.1.js:1
do_icall @ 00aba26a:0x194de5
do_icall_wrapper @ 00aba26a:0x79df9
interp_exec_method @ 00aba26a:0x44ad3
interp_runtime_invoke @ 00aba26a:0x12efff
mono_jit_runtime_invoke @ 00aba26a:0x118e5f
do_runtime_invoke @ 00aba26a:0x79d42
mono_runtime_try_invoke @ 00aba26a:0x12982
mono_runtime_invoke @ 00aba26a:0x10ec2b
mono_wasm_invoke_method @ 00aba26a:0x108e48
Module._mono_wasm_invoke_method @ dotnet.5.0.1.js:1
call_method @ dotnet.5.0.1.js:1
(anonymous) @ dotnet.5.0.1.js:1
endInvokeJSFromDotNet @ blazor.webassembly.js:1
(anonymous) @ blazor.webassembly.js:1
Promise.then (async)
beginInvokeJSFromDotNet @ blazor.webassembly.js:1
w @ blazor.webassembly.js:1
_mono_wasm_invoke_js_blazor @ dotnet.5.0.1.js:1
do_icall @ 00aba26a:0x194e58
do_icall_wrapper @ 00aba26a:0x79df9
interp_exec_method @ 00aba26a:0x44ad3
interp_runtime_invoke @ 00aba26a:0x12efff
mono_jit_runtime_invoke @ 00aba26a:0x118e5f
do_runtime_invoke @ 00aba26a:0x79d42
mono_runtime_try_invoke @ 00aba26a:0x12982
mono_runtime_invoke @ 00aba26a:0x10ec2b
mono_wasm_invoke_method @ 00aba26a:0x108e48
Module._mono_wasm_invoke_method @ dotnet.5.0.1.js:1
call_method @ dotnet.5.0.1.js:1
(anonymous) @ dotnet.5.0.1.js:1
endInvokeJSFromDotNet @ blazor.webassembly.js:1
(anonymous) @ blazor.webassembly.js:1
Promise.then (async)
beginInvokeJSFromDotNet @ blazor.webassembly.js:1
w @ blazor.webassembly.js:1
_mono_wasm_invoke_js_blazor @ dotnet.5.0.1.js:1
do_icall @ 00aba26a:0x194e58
do_icall_wrapper @ 00aba26a:0x79df9
interp_exec_method @ 00aba26a:0x44ad3
interp_runtime_invoke @ 00aba26a:0x12efff
mono_jit_runtime_invoke @ 00aba26a:0x118e5f
do_runtime_invoke @ 00aba26a:0x79d42
mono_runtime_invoke_checked @ 00aba26a:0xf65d
mono_runtime_try_invoke_array @ 00aba26a:0x10e831
ves_icall_InternalInvoke @ 00aba26a:0xed492
ves_icall_InternalInvoke_raw @ 00aba26a:0xecf57
do_icall @ 00aba26a:0x194de5
do_icall_wrapper @ 00aba26a:0x79df9
interp_exec_method @ 00aba26a:0x44ad3
interp_runtime_invoke @ 00aba26a:0x12efff
mono_jit_runtime_invoke @ 00aba26a:0x118e5f
do_runtime_invoke @ 00aba26a:0x79d42
mono_runtime_try_invoke @ 00aba26a:0x12982
mono_runtime_invoke @ 00aba26a:0x10ec2b
mono_wasm_invoke_method @ 00aba26a:0x108e48
Module._mono_wasm_invoke_method @ dotnet.5.0.1.js:1
call_method @ dotnet.5.0.1.js:1
(anonymous) @ dotnet.5.0.1.js:1
beginInvokeDotNetFromJS @ blazor.webassembly.js:1
h @ blazor.webassembly.js:1
e.invokeMethodAsync @ blazor.webassembly.js:1
(anonymous) @ blazor.webassembly.js:1
(anonymous) @ blazor.webassembly.js:1
(anonymous) @ blazor.webassembly.js:1
(anonymous) @ blazor.webassembly.js:1
r @ blazor.webassembly.js:1
(anonymous) @ blazor.webassembly.js:1
(anonymous) @ blazor.webassembly.js:1
(anonymous) @ blazor.webassembly.js:1
(anonymous) @ blazor.webassembly.js:1
(anonymous) @ blazor.webassembly.js:1
r @ blazor.webassembly.js:1
d @ blazor.webassembly.js:1
f @ blazor.webassembly.js:1
(anonymous) @ blazor.webassembly.js:1
(anonymous) @ blazor.webassembly.js:1
e.onGlobalEvent @ blazor.webassembly.js:1
Show 44 more frames

如何解决?

【问题讨论】:

【参考方案1】:

这是你应该如何调用确认方法:

bool isConfirmed = await JsRuntime.InvokeAsync<bool>("confirm", "Bạn có chắc chắn muốn xóa ?");

【讨论】:

以上是关于Microsoft.JSInterop.JSException:当前没有元素与组件关联的主要内容,如果未能解决你的问题,请参考以下文章