How To Reference a Specific Column In an Event Handler

132 views Asked by At

I'm using the default ActionBeginHandler to determine what action to take after a user has selected Add, Edit or Delete in a Blazor Syncfusion datagrid. My aim is to make the component reusable with generic type parameters. Ahead of doing that, I can get it to work when i use a specific entity model class in the ActionEventArgs but not when I pass in a generic TItem type parameter for the entity model class. In other words:

This works fine and it retrieves the value of args.Data.EmployeeName:

        public async void ActionBeginHandler(ActionEventArgs<**Employee**> args)
        {
            if (args.RequestType.Equals(Syncfusion.Blazor.Grids.Action.Save))
            {
                if (args.Action == "Add")
                {
                    if (args.Data.**EmployeeName** == null)
                    {
                        return;
                    }
                    else
                        ... add the record;
                    }
                }
            }
        }

but I don't know how to reference the column name for another (generic) entity model (say Products). How do I reference the same args.Data column generically.

I initially thought something like this might work but it didn't and there doesn't seem to be any way of referencing either the name or index of an args.Data column, other than by hard-coding it.

    public async void ActionBeginHandler(ActionEventArgs<**TItem**> args)
    {
        if (args.RequestType.Equals(Syncfusion.Blazor.Grids.Action.Save))
        {
            if (args.Action == "Add")
            {
                if (args.Data.[Columns[generic column name or index] == null)
                {
                    return;
                }
                else
                    ... add the record;
                }
            }
        }
    }

I am still learning Blazor so if there are fundamental concepts I'm missing I'm happy to take any advice to help me resolve the issue.

0

There are 0 answers