Blazor Web assembly:错误 CS0131:赋值的左侧必须是变量、属性或索引器

Muc*_*Bey 9 blazor blazor-webassembly

我正在使用 Blazor WebAssembly RC2。我目前正在创建一个基本组件,它只是一个表单。我遇到了一些我无法解决的奇怪错误。它没有编译。

\n

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

\n

编译错误:

\n
/.../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]\n/.../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]\n/.../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]\n/.../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]\n/.../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]\n/.../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]\n
Run Code Online (Sandbox Code Playgroud)\n

组件:

\n
@inject IProfessorService ProfessorService\n\n<EditForm OnValidSubmit="@Submit" Model="_registerThesisDto">\n    <ValidationSummary/>\n    <DataAnnotationsValidator/>\n\n    <div class="container">\n        <div class="row">\n            <div class="col-5 align-self-center">\n                Nachname:\n            </div>\n            <div class="col-7 align-self-center">\n                @Student.LastName\n            </div>\n        </div>\n        <div class="row">\n            <div class="col-5 align-self-center">\n                Vorname:\n            </div>\n            <div class="col-7 align-self-center">\n                @Student.FirstName\n            </div>\n        </div>\n        <div class="row">\n            <div class="col-5 align-self-center">\n                Anschrift:\n            </div>\n            <div class="col-7 align-self-center">\n                @Student.PostalAddress\n            </div>\n        </div>\n        <div class="row">\n            <div class="col-5 align-self-center">\n                Matrikelnummer:\n            </div>\n            <div class="col-7 align-self-center">\n                @Student.MatriculationNumber\n            </div>\n        </div>\n        <div class="row">\n            <div class="col-5 align-self-center">\n                Studiengang:\n            </div>\n            <div class="col-7 align-self-center">\n                @Student.Course?.Acronym\n            </div>\n        </div>\n        <div class="row">\n            <div class="col-5 align-self-center">\n                Schwerpunkt (nur M.Sc.):\n            </div>\n            <div class="col-7 align-self-center">\n                <RadzenTextBox @bind-Value="_registerThesisDto?.Focus" Style="width: 100%"></RadzenTextBox>\n            </div>\n        </div>\n        <div class="row">\n            <div class="col-5 align-self-center">\n                Title der Arbeit:\n            </div>\n            <div class="col-7 align-self-center">\n                <RadzenTextArea @bind-Value="_registerThesisDto?.ThesisTitle" Style="width: 100%"></RadzenTextArea>\n            </div>\n        </div>\n        <div class="row">\n            <div class="col-5 align-self-center">\n                Bearbeitung:\n            </div>\n            <div class="col-7 align-self-center">\n                <RadzenTextBox PlaceHolder="Im Haus / Firma" @bind-Value="_registerThesisDto?.Where" Style="width: 100%"></RadzenTextBox>\n            </div>\n        </div>\n        <div class="row">\n            <div class="col-5 align-self-center">\n                Erstpr\xc3\xbcfer:\n            </div>\n            <div class="col-7 align-self-center">\n                <RadzenDropDown AllowClear="true"\n                                Style="width: 100%"\n                                FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive"\n                                FilterOperator="StringFilterOperator.Contains" AllowFiltering="true"\n                                Data="@_professors" TextProperty="FullName" ValueProperty="Id"\n                                @bind-Value="_registerThesisDto?.FirstExaminerId"/>\n            </div>\n        </div>\n        <div class="row">\n            <div class="col-5 align-self-center">\n                Zweitpr\xc3\xbcfer:\n            </div>\n            <div class="col-7 align-self-center">\n                <RadzenDropDown AllowClear="true"\n                                Style="width: 100%"\n                                FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive"\n                                FilterOperator="StringFilterOperator.Contains" AllowFiltering="true"\n                                Data="@_professors" TextProperty="FullName" ValueProperty="Id"\n                                @bind-Value="_registerThesisDto?.SecondExaminerId"/>\n            </div>\n        </div>\n        <div class="row justify-content-center" style="margin-top: 3%">\n            <MatButton Raised="true" Type="submit">Formular einreichen</MatButton>\n        </div>\n    </div>\n</EditForm>\n\n\n@code {\n    [Parameter] public ThesisRegistrationDto Registration { get; set; }\n    [Parameter] public StudentDto Student { get; set; }\n    [Parameter] public EventCallback<RegisterThesisDto> OnSubmit { get; set; }\n\n    private RegisterThesisDto _registerThesisDto;\n    private IEnumerable<UserDto> _professors = new List<UserDto>();\n\n    protected override async Task OnInitializedAsync()\n    {\n        _professors = await ProfessorService.GetProfessorsOfFaculty(Student.Faculty.Id);\n    }\n\n    protected override async Task OnParametersSetAsync()\n    {\n        await base.OnParametersSetAsync();\n        _registerThesisDto = new RegisterThesisDto\n        {\n            Focus = Registration.Focus,\n            Where = Registration.Where,\n            StudentId = Student.Id,\n            ThesisTitle = Registration.ThesisTitle,\n            FirstExaminerId = Registration.FirstExaminer.Id,\n            SecondExaminerId = Registration.SecondExaminer.Id\n        };\n    }\n\n    private async Task Submit()\n    {\n        await OnSubmit.InvokeAsync(_registerThesisDto);\n    }\n\n}\n
Run Code Online (Sandbox Code Playgroud)\n

需要一些帮助。谢谢

\n

Mis*_*goo 2

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

@bind-Value="_registerThesisDto?.FirstExaminerId"

使用条件代替

@if (_registerThesisDto != null)
{
  <EditForm OnValidSubmit="@Submit" Model="_registerThesisDto">
  ...
  </EditForm>
}
Run Code Online (Sandbox Code Playgroud)

然后您就可以安全地绑定而无需进行空检查。

@bind-Value="_registerThesisDto.FirstExaminerId"
Run Code Online (Sandbox Code Playgroud)