0

I'm just starting to learn Blazor and I have a problem, I made a simple crud app with Blazor Telerik and everything works but I can't save any changes to my app

Unhandled exception rendering component: Value cannot be null. (Parameter 'source') System.ArgumentNullException: Value cannot be null. (Parameter 'source') at System.Linq.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument) at System.Linq.Enumerable.TryGetFirst[Uzytkowniccy](IEnumerable1 source, Func2 predicate, Boolean& found) at System.Linq.Enumerable.First[Uzytkowniccy](IEnumerable1 source, Func2 predicate) at

Here is GridData

TelerikGrid Data=@uzytkownicy Sortable="true" Pageable="true" Height="300px">
    <GridToolBar>
        <TelerikButton OnClick="@DodajU">Dodaj użytkownika</TelerikButton>
        <GridSearchBox DebounceDelay="200"></GridSearchBox>
    </GridToolBar>
    <GridColumns>
        <GridColumn Field=@nameof(Uzytkowniccy.Imie) Title="Imie" Editable="true" />

...
 <GridCommandButton Command="Edit" Icon="edit" OnClick="@EdytujRekord">Edycja</GridCommandButton>
            <GridCommandButton Command="Delete" Icon="delete" OnClick="@DeleteItem">Usuń</GridCommandButton>

This is my Window Form Edit

TelerikWindow Visible="@isVisible" VisibleChanged="VisibleChangedHandler" Width="1100px" Height="400px" Centered="true" Modal="true">
    <WindowTitle>
        <strong>@TytulOkna</strong>
    </WindowTitle>
    <WindowContent>
        <TelerikForm Model="@uzytkownik" OnValidSubmit="@OnValidSubmit" ValidationMessageType="@FormValidationMessageType.Inline" Class="my-telerik-form" Columns="3" ColumnSpacing="25px">
            <FormValidation>
                <DataAnnotationsValidator />
            </FormValidation>

....

 <FormButtons>
                <TelerikButton ButtonType="@ButtonType.Submit" Primary="true">Zapisz</TelerikButton>
                <TelerikButton OnClick="@CloseWindow" ButtonType="ButtonType.Button">Zamknij</TelerikButton>
            </FormButtons>
        </TelerikForm>

And here is my C# code there are add edit and delete methods in C # code

    [Parameter] public Uzytkowniccy uzytkownik { get; set; }
    [Parameter] public EventCallback OnValidSubmit { get; set; }
    private string TytulOkna { get; set; }

    bool isVisible { get; set; }
    string result { get; set; }
    bool Dodaj { get; set; }
    bool Record { get; set; }

 public void DodajU()
    {
        Record = true;
        uzytkownik = new Uzytkowniccy();
        uzytkownik.Imie = uzytkownik.Nazwisko = uzytkownik.Email = uzytkownik.Email = uzytkownik.Login = uzytkownik.Password = uzytkownik.PPassword = String.Empty;
        isVisible = true;
    }

    public void EdytujRekord(GridCommandEventArgs args)
    {
        Record = false;
        uzytkownik = (args.Item as Uzytkowniccy);
        isVisible = true;
    }

   async Task DeleteItem(GridCommandEventArgs args)
    {
        var argsItem = (Uzytkowniccy)args.Item;
        var httpResponseMessage = await Http.DeleteAsync($"api/uzytkownicy/{argsItem.Id}");
        if (httpResponseMessage.IsSuccessStatusCode)
        {
            uzytkownicy.Remove(argsItem);
        }
    }

This is part which doesnt work

 async Task OnValidSubmit(object obj)
    {
        if (obj != null)
        {
            if (Record)
            {
                var ToUpdate = uzytkownicy.First(p => p.Id == uzytkownik.Id);
                ToUpdate.Imie = uzytkownik.Imie;
                ToUpdate.Nazwisko = uzytkownik.Nazwisko;
                ToUpdate.Email = uzytkownik.Email;
                ToUpdate.Login = uzytkownik.Login;
                ToUpdate.Password = uzytkownik.Password;
                ToUpdate.PPassword = uzytkownik.PPassword;
                ToUpdate.TypUzytkownika = uzytkownik.TypUzytkownika;

                await Http.PutAsJsonAsync<Uzytkowniccy>($"api/uzytkownicy/{uzytkownik.Id}", uzytkownik);
            }
           
        }

       
        isVisible = false;

    }
    }
  • Your grid has `TelerikGrid Data=@uzytkownicy` and it looks like uzytkownicy is null until a grid toolbar button is clicked and DodajU runs, but I have a slight concern that if the grid tries to render itself before this that the data source being null might cause a problem (I don't work with telerik but other libraries I have used have had similar behaviors).. what happens if you make like `public Uzytkowniccy uzytkownik { get; set; } = new()` ? Also curious; is Uzytkowniccy a collection of some kind? – Caius Jard Nov 30 '21 at 19:11
  • The parameter name in the c# is different than what you have set to the Data parameter of the grid. – rdmptn Dec 02 '21 at 10:56
  • Also, you have three very similar threads, it seems you are having a hard time with something and I suggest you contact Telerik directly, they do offer support with your license – rdmptn Dec 02 '21 at 10:57

0 Answers0