我正在尝试捕获由VS Community 2019开发的Blazor Wasm表中的表输入和更改。我能够捕获onkeydown(这只为我提供了按键信息,但没有显示按下表的位置),但我似乎无法抓住输入或变化。 here文档并没有太大帮助。我想念什么吗?我需要通过JavaScript来做到这一点吗?
更新:除了在浏览器窗口中没有错误指示的事实之外,不确定我是怎么错过这个的,但是在将OnKeyDown处理程序写入控制台后,我的代码下方显示的异常记录在控制台中。
这是我的表数据Blazor标记和事件处理程序:
<td contenteditable="true"
@onchange="Cell_OnChange"
@oninput="Cell_OnInput"
@onkeydown="Cell_OnKeyDown">
@TableValue
</td>
private void Cell_OnChange(ChangeEventArgs e)
{
Console.WriteLine("OnChange");
}
private void Cell_OnInput(ChangeEventArgs e)
{
Console.WriteLine("OnInput");
}
private void Cell_OnKeyDown(KeyboardEventArgs e)
{
Console.WriteLine("OnKeyDown");
}
控制台中显示的异常:
blazor.webassembly.js:1 Uncaught (in promise) Error:
System.InvalidOperationException: There was an error parsing the event arguments. EventId: '1500'. ---> System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.AspNetCore.Components.Web.WebEventData.DeserializeChangeEventArgs (System.String eventArgsJson) <0x3626798 + 0x0001e> in <filename unknown>:0
at Microsoft.AspNetCore.Components.Web.WebEventData.ParseEventArgsJson (System.UInt64 eventHandlerId, System.String eventArgsType, System.String eventArgsJson) <0x33bc230 + 0x00206> in <filename unknown>:0
--- End of inner exception stack trace ---
at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)
at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) <0x2868918 + 0x000ce> in <filename unknown>:0
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.InvokeSynchronously (Microsoft.JSInterop.JSRuntime jsRuntime, Microsoft.JSInterop.Infrastructure.DotNetInvocationInfo& callInfo, Microsoft.JSInterop.Infrastructure.IDotNetObjectReference objectReference, System.String argsJson) <0x3c67378 + 0x0017a> in <filename unknown>:0
at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.BeginInvokeDotNet (Microsoft.JSInterop.JSRuntime jsRuntime, Microsoft.JSInterop.Infrastructure.DotNetInvocationInfo invocationInfo, System.String argsJson) <0x3c66d20 + 0x0009e> in <filename unknown>:0
at Object.endInvokeDotNetFromJS (https://localhost:44307/_framework/blazor.webassembly.js:1:10049)
at Object.invokeJSFromDotNet (https://localhost:44307/_framework/blazor.webassembly.js:1:9669)
at _mono_wasm_invoke_js_marshalled (https://localhost:44307/_framework/wasm/dotnet.3.2.0.js:1:171433)
at do_icall (<anonymous>:wasm-function[6049]:0x10f8b1)
at do_icall_wrapper (<anonymous>:wasm-function[1896]:0x50b6a)
at interp_exec_method (<anonymous>:wasm-function[1120]:0x2588e)
at interp_runtime_invoke (<anonymous>:wasm-function[5655]:0xf7391)
at mono_jit_runtime_invoke (<anonymous>:wasm-function[5109]:0xddb3d)
at do_runtime_invoke (<anonymous>:wasm-function[1410]:0x3ba85)
at mono_runtime_try_invoke (<anonymous>:wasm-function[418]:0xcfdb)
endInvokeDotNetFromJS @ blazor.webassembly.js:1
invokeJSFromDotNet @ blazor.webassembly.js:1
_mono_wasm_invoke_js_marshalled @ dotnet.3.2.0.js:1
do_icall @ 00755c3a:1
do_icall_wrapper @ 00755c3a:1
interp_exec_method @ 00755c3a:1
interp_runtime_invoke @ 00755c3a:1
mono_jit_runtime_invoke @ 00755c3a:1
do_runtime_invoke @ 00755c3a:1
mono_runtime_try_invoke @ 00755c3a:1
mono_runtime_invoke @ 00755c3a:1
mono_wasm_invoke_method @ 00755c3a:1
Module._mono_wasm_invoke_method @ dotnet.3.2.0.js:1
call_method @ dotnet.3.2.0.js:1
(anonymous) @ dotnet.3.2.0.js:1
beginInvokeDotNetFromJS @ blazor.webassembly.js:1
s @ blazor.webassembly.js:1
e.invokeMethodAsync @ blazor.webassembly.js:1
(anonymous) @ blazor.webassembly.js:1
t.dispatchEvent @ blazor.webassembly.js:1
(anonymous) @ blazor.webassembly.js:1
(anonymous) @ blazor.webassembly.js:1
e.onGlobalEvent @ blazor.webassembly.js:1