首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >错误CS0131:赋值的左边必须是变量、属性或索引器。

错误CS0131:赋值的左边必须是变量、属性或索引器。
EN

Stack Overflow用户
提问于 2020-10-24 16:45:17
回答 1查看 1.8K关注 0票数 8

我用的是blazor组件RC2。我目前正在创建一个基本组件,它只是一个表单。我遇到了一些我无法解决的奇怪错误。这不是在汇编。

它说我的作业有问题,但我没有看到任何错误或语法错误。

编译错误:

代码语言:javascript
复制
/.../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]

构成部分:

代码语言:javascript
复制
@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);
    }

}

需要帮助。谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-11-15 14:31:56

尝试从绑定中删除所有空检查,我不认为它会喜欢这样的事情

@bind-Value="_registerThesisDto?.FirstExaminerId"

使用条件代替

代码语言:javascript
复制
@if (_registerThesisDto != null)
{
  <EditForm OnValidSubmit="@Submit" Model="_registerThesisDto">
  ...
  </EditForm>
}

然后,您可以安全地绑定,而不需要进行空检查。

代码语言:javascript
复制
@bind-Value="_registerThesisDto.FirstExaminerId"
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64515795

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档