Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
50
Grid event JavaScript to .Net
posted

I have a Blazor WebAssembly app using IgbGrid.  I need to pass the results of the RowEditDoneScript from the JavaScript script to a .Net method for processing.  I have code that can successfully pass a string to .Net, but it fails if I try to pass the event args.  Here are the relevant parts of the code that works:

event.js

var GLOBAL = {};
GLOBAL.DotNetReference = null;
GLOBAL.SetDotnetReference = function (objRef) {
GLOBAL.DotNetReference = objRef;
};

igRegisterScript("EvtRowEditDone", (event) => {
var d = event.detail;
GLOBAL.DotNetReference.invokeMethod("ProcessEvt", "Hello");
}, false);

EvetTicketEdit.razor

@page "/eventticketedit"
@implements IDisposable
@inject IJSRuntime js

//in grid def

RowEditDoneScript="EvtRowEditDone"
RowEditable="true"

private DotNetObjectReference<EventTicketEdit>? objRef;

protected async override Task OnAfterRenderAsync(bool firstRender)
{
var grid = this.grid;
if (firstRender)
{
objRef = DotNetObjectReference.Create(this);
await js.InvokeVoidAsync("GLOBAL.SetDotnetReference", objRef);
}
}

[JSInvokable("ProcessEvt")]
public void ProcessEvt(string x)
{

}

public void Dispose()
{
objRef?.Dispose();
}

If I change the script to:

igRegisterScript("EvtRowEditDone", (event) => {
var d = event.detail;
GLOBAL.DotNetReference.invokeMethod("ProcessEvt", event);
}, false);

And change the .razor code to:

[JSInvokable("ProcessEvt")]
public void ProcessEvt(IgbGridEditDoneEventArgs x)
{

}

It appears to run successfully, but the EventArgs fields contain no data.  In the script, I can see data in event.detail, but detail is blank at the ,Net end.

Can you provide an example of how I should be passing this data?

Parents Reply Children
No Data