MucoBey
MucoBey

Reputation: 191

Blazor Webassembly: error CS0131: The left-hand side of an assignment must be a variable, property or indexer

I'm using blazor webassembly RC2. I'm currently creating a basic component, which is just a form. I'm getting some weird errors which I can not solve. It is not compiling.

It says there are problems with my assignments, but I can not see any typo or syntax error.

The compile-errors:

/.../net5.0/Razor/Components/Dashboard/ThesisRegistrationEditForm.razor.g.cs(314,388): error CS0131: The left-hand side of an assignment must be a variable, property or indexer [.../Client/VerwaltungAbschlussarbeiten.Client.csproj]
/.../Client/obj/Debug/net5.0/Razor/Components/Dashboard/ThesisRegistrationEditForm.razor.g.cs(336,388): error CS0131: The left-hand side of an assignment must be a variable, property or indexer [.../Client/VerwaltungAbschlussarbeiten.Client.csproj]
/.../Client/obj/Debug/net5.0/Razor/Components/Dashboard/ThesisRegistrationEditForm.razor.g.cs(359,388): error CS0131: The left-hand side of an assignment must be a variable, property or indexer [.../Client/VerwaltungAbschlussarbeiten.Client.csproj]
/.../Client/obj/Debug/net5.0/Razor/Components/Dashboard/ThesisRegistrationEditForm.razor.g.cs(418,199): error CS0131: The left-hand side of an assignment must be a variable, property or indexer [/.../Client/VerwaltungAbschlussarbeiten.Client.csproj]
/.../Client/obj/Debug/net5.0/Razor/Components/Dashboard/ThesisRegistrationEditForm.razor.g.cs(475,200): error CS0131: The left-hand side of an assignment must be a variable, property or indexer [/.../Client/VerwaltungAbschlussarbeiten.Client.csproj]
/.../Client/obj/Debug/net5.0/Razor/Components/Dashboard/ThesisRegistrationEditForm.razor.g.cs(204,168): error CS1662: Cannot convert lambda expression to intended delegate type because some of the return types in the block are not implicitly convertible to the delegate return type [/.../Client/VerwaltungAbschlussarbeiten.Client.csproj]

The component:

@inject IProfessorService ProfessorService

<EditForm OnValidSubmit="@Submit" Model="_registerThesisDto">
    <ValidationSummary/>
    <DataAnnotationsValidator/>

    <div class="container">
        <div class="row">
            <div class="col-5 align-self-center">
                Nachname:
            </div>
            <div class="col-7 align-self-center">
                @Student.LastName
            </div>
        </div>
        <div class="row">
            <div class="col-5 align-self-center">
                Vorname:
            </div>
            <div class="col-7 align-self-center">
                @Student.FirstName
            </div>
        </div>
        <div class="row">
            <div class="col-5 align-self-center">
                Anschrift:
            </div>
            <div class="col-7 align-self-center">
                @Student.PostalAddress
            </div>
        </div>
        <div class="row">
            <div class="col-5 align-self-center">
                Matrikelnummer:
            </div>
            <div class="col-7 align-self-center">
                @Student.MatriculationNumber
            </div>
        </div>
        <div class="row">
            <div class="col-5 align-self-center">
                Studiengang:
            </div>
            <div class="col-7 align-self-center">
                @Student.Course?.Acronym
            </div>
        </div>
        <div class="row">
            <div class="col-5 align-self-center">
                Schwerpunkt (nur M.Sc.):
            </div>
            <div class="col-7 align-self-center">
                <RadzenTextBox @bind-Value="_registerThesisDto?.Focus" Style="width: 100%"></RadzenTextBox>
            </div>
        </div>
        <div class="row">
            <div class="col-5 align-self-center">
                Title der Arbeit:
            </div>
            <div class="col-7 align-self-center">
                <RadzenTextArea @bind-Value="_registerThesisDto?.ThesisTitle" Style="width: 100%"></RadzenTextArea>
            </div>
        </div>
        <div class="row">
            <div class="col-5 align-self-center">
                Bearbeitung:
            </div>
            <div class="col-7 align-self-center">
                <RadzenTextBox PlaceHolder="Im Haus / Firma" @bind-Value="_registerThesisDto?.Where" Style="width: 100%"></RadzenTextBox>
            </div>
        </div>
        <div class="row">
            <div class="col-5 align-self-center">
                Erstprüfer:
            </div>
            <div class="col-7 align-self-center">
                <RadzenDropDown AllowClear="true"
                                Style="width: 100%"
                                FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive"
                                FilterOperator="StringFilterOperator.Contains" AllowFiltering="true"
                                Data="@_professors" TextProperty="FullName" ValueProperty="Id"
                                @bind-Value="_registerThesisDto?.FirstExaminerId"/>
            </div>
        </div>
        <div class="row">
            <div class="col-5 align-self-center">
                Zweitprüfer:
            </div>
            <div class="col-7 align-self-center">
                <RadzenDropDown AllowClear="true"
                                Style="width: 100%"
                                FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive"
                                FilterOperator="StringFilterOperator.Contains" AllowFiltering="true"
                                Data="@_professors" TextProperty="FullName" ValueProperty="Id"
                                @bind-Value="_registerThesisDto?.SecondExaminerId"/>
            </div>
        </div>
        <div class="row justify-content-center" style="margin-top: 3%">
            <MatButton Raised="true" Type="submit">Formular einreichen</MatButton>
        </div>
    </div>
</EditForm>


@code {
    [Parameter] public ThesisRegistrationDto Registration { get; set; }
    [Parameter] public StudentDto Student { get; set; }
    [Parameter] public EventCallback<RegisterThesisDto> OnSubmit { get; set; }

    private RegisterThesisDto _registerThesisDto;
    private IEnumerable<UserDto> _professors = new List<UserDto>();

    protected override async Task OnInitializedAsync()
    {
        _professors = await ProfessorService.GetProfessorsOfFaculty(Student.Faculty.Id);
    }

    protected override async Task OnParametersSetAsync()
    {
        await base.OnParametersSetAsync();
        _registerThesisDto = new RegisterThesisDto
        {
            Focus = Registration.Focus,
            Where = Registration.Where,
            StudentId = Student.Id,
            ThesisTitle = Registration.ThesisTitle,
            FirstExaminerId = Registration.FirstExaminer.Id,
            SecondExaminerId = Registration.SecondExaminer.Id
        };
    }

    private async Task Submit()
    {
        await OnSubmit.InvokeAsync(_registerThesisDto);
    }

}

need some help. thank you

Upvotes: 9

Views: 3266

Answers (1)

Mister Magoo
Mister Magoo

Reputation: 9029

Try removing all the null checks from the binding, I don't think it will like this sort of thing

@bind-Value="_registerThesisDto?.FirstExaminerId"

Use a conditional instead

@if (_registerThesisDto != null)
{
  <EditForm OnValidSubmit="@Submit" Model="_registerThesisDto">
  ...
  </EditForm>
}

Then you can safely bind without the null check.

@bind-Value="_registerThesisDto.FirstExaminerId"

Upvotes: 4

Related Questions