Closed
Description
Describe the bug
I have a generic component wich need some Js interaction. My component is an autocomplete wich listen on the keypress event to launch research. Whe i try invoke c# method from Js, I have this following Js error
"Error: System.InvalidOperationException: Late bound operations cannot be performed on types or methods for which ContainsGenericParameters is true.
"
To Reproduce
create a generic component, which contain an input type text
@typeparam TItem
@inherits AutoCompleteViewModel<TItem>
<input type="text" id="@Id" class="form-control" value="@Value"> `
register js on render
protected override async Task OnAfterRenderAsync()
{
this.JsRuntime.InvokeAsync<object>("listenAutoComplete", this.Id, new DotNetObjectRef(this));
await base.OnAfterRenderAsync();
}
[JSInvokable]
public void SynchroniseValue(string value)
{
if(this.Value != value)
{
this.Value = value;
this.LaunchResearch();
}
}
function listenAutoComplete(id, control) {
$("#" + id).keyup(function () {
var value = $(this).val();
control.invokeMethodAsync('SynchroniseValue', value);
});
}
Expected behavior
Have a way to call C# method without error
Additional context
My first idea was to use the key-* event of razor, but i was unable to have a satisfaying behavior with ths events (unable to retrieve the current value of my input, binding seem only fire when control lost focus), so i decided to switch on js.
If you have another solution, i take it ;-)