Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

"this" is not avaible in the current context with EventCallback.Factory.Create [duplicate]

$
0
0

Here is my code:

private readonly Dictionary<string, ComponentMetadata> components = new()    {        [nameof(ChoiceOfAnswerQuestion)] = new ComponentMetadata()        {            Type = typeof(ChoiceOfAnswerQuestion),            Name = "Choix multiple",            Parameters = {                { nameof(ChoiceOfAnswerQuestion.OnValidSubmit), EventCallback.Factory.Create(this, HandleValidSubmit) },                { nameof(ChoiceOfAnswerQuestion.OnCancel), EventCallback.Factory.Create(this, CancelEdit) }            }        },        [nameof(AssociationQuestion)] = new ComponentMetadata()        {            Type = typeof(AssociationQuestion),            Name = "Association",            Parameters = {                { nameof(AssociationQuestion.OnValidSubmit), EventCallback.Factory.Create(this, HandleValidSubmit) },                { nameof(AssociationQuestion.OnCancel), EventCallback.Factory.Create(this, CancelEdit) }            }        }    };

...

private async Task DeleteQuestion(int questionId){    ...}

...

private async Task HandleValidSubmit(){    ...}

The error occurs at "this". I don't know why but it doesn't take the "this". This is the complete message:

Keywork 'this' is not available in the current context

It should works, because my callback doesn't has argument and I should not pass any return type to the create because the functions are Task.

By the way, I've followed the EventCallBack section here:https://learn.microsoft.com/en-us/aspnet/core/blazor/components/dynamiccomponent?view=aspnetcore-8.0

Maybe you can help me?


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>