Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot reference non-static field in RowRemoving on Datagrid #1556

Closed
LouiseAJensen opened this issue Dec 1, 2020 · 4 comments
Closed

Cannot reference non-static field in RowRemoving on Datagrid #1556

LouiseAJensen opened this issue Dec 1, 2020 · 4 comments

Comments

@LouiseAJensen
Copy link

LouiseAJensen commented Dec 1, 2020

I'm experiencing the exact same issue as is described here:
#570

I'm getting this error:
A field initializer cannot reference the non-static field, method, or property 'DepartmentOverviewPage_.DeleteCase(string)'

I have:

private Action<CancellableRowChange<model.Department>> OnRowRemoving = o =>
{
    o.Cancel = DeleteCase(o.Item.DepartmentID); // can't call non-static method
};

private bool DeleteCase(string id)  // If this is static, then I can't use JsRuntime
{
    bool confirmed = JSRuntime.InvokeAsync<bool>("confirm", "Are you sure?").Result;
    if (confirmed)
    {
        return true;
        // Delete!
     }
     return false;
}

My version is
image

@stsrki
Copy link
Collaborator

stsrki commented Dec 1, 2020

You have this Action<CancellableRowChange<model.Department>>. What is the model.Department? Is it a data-type or is it a object field or member?

@LouiseAJensen
Copy link
Author

It is the data-type that I'm using as a TItem in my Datagrid

@stsrki
Copy link
Collaborator

stsrki commented Dec 1, 2020

I will need to see your models and a sample of DataGrid usage. If possible full reproducible sample would be great.

@stsrki stsrki closed this as completed Jun 22, 2021
@rgomezia
Copy link

rgomezia commented Dec 29, 2021

Hi , I have the same problem ¿ how can i solved this or view some example ?
On my Grid i use RowRemoving="@OnRowRemoving" and use exactly this code from issue
#570, but not working i have version 9.5.3

` private Action<CancellableRowChange> OnRowRemoving = o =>
{
o.Cancel = DeleteArea(o.Item.Code);
};

private bool DeleteArea(string usuarioCode)  
{
    bool confirmed = JS.InvokeAsync<bool>("Confirmar", "Confirmar", "¿Seguro que deseas quitar esta area?", "question").Result;
    if (confirmed)
    {
        var resp = Http.DeleteAsync($"DeleteUsuarioArea/{sessionTest.TokenAplicacion}/{usuarioArea.Code}");
        var data = Http.GetFromJsonAsync<List<UsuarioArea>>($"GetUsuarioArea/{sessionTest.TokenAplicacion}/{tempUsuario.usuarioSAP}");
        lstUsuarioArea = data.Result.Where(x => x.USER_CODE == tempUsuario.usuarioSAP).ToList();
        lstAreaToAdd = lstArea.Where(x => !data.Result.Any(z => z.U_SP_IdArea == x.Code)).ToList();
        StateHasChanged();  
        return true;
    }
    return false;
}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants