I am learning about EventCallBack with blazor, but i wanted to know
- Is there a way for my return method to return a second argument on the parent side. I would like to know the rowID that it came from
Parent Code
@foreach (var rw in pg.rows)
{
@if (rw.rowDef == 1)
{
@if (rw.widgetsSection1.Count == 0)
{
<AddWidgetToColumnComponent rowID="rw.rowID" onAddingWidget="AddWidgetToRow"></AddWidgetToColumnComponent>
}
}
}
}
@code{
...
private void AddWidgetToRow(GenericWidgets evnt)
{
//bool confirmed = await JsRuntime.InvokeAsync<bool>("confirm", "Are you sure?");
var row = pg.rows.Where(x => x.rowID == 3).FirstOrDefault();
//row.addWidgetSection1(widgets);
}
}
Child Component AddWidgetToColumnComponent
<button class="btn btn-info" @onclick="@addComponent">Ajouter</button>
@code {
[Parameter]
public int rowID { get; set; }
[Parameter]
public EventCallback<GenericWidgets> onAddingWidget { get; set; }
public async void addComponent()
{
GenericWidgets widget = new GenericWidgets();
await onAddingWidget.InvokeAsync(widget);
}
I am not sure how to accomplish this, if possible (debugger give me error). The only other way would be to change my generic class to add the rowID attribute in it. But is there an other way?
Change the lines ( what i would like it to be)
<AddWidgetToColumnComponent rowID="rw.rowID" onAddingWidget="AddWidgetToRow(rw.rowID)"></AddWidgetToColumnComponent>
and this line
private void AddWidgetToRow(GenericWidgets evnt, int rowID)