我使用的是blazor webassembly RC2。我目前正在创建一个基本组件,这只是一个表单。我遇到了一些无法解决的奇怪错误。它不是在编译。
上面说我的作业有问题,但我看不到任何拼写错误或语法错误。
编译错误:
/.../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]
组件:
@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);
}
}
需要一些帮助。谢谢
尝试从绑定中删除所有空检查,我认为它不会喜欢这样的东西
@bind-Value="_registerThesisDto?.FirstExaminerId"
使用条件
@if (_registerThesisDto != null)
{
<EditForm OnValidSubmit="@Submit" Model="_registerThesisDto">
...
</EditForm>
}
然后您可以安全地绑定,而不需要进行null检查。
@bind-Value="_registerThesisDto.FirstExaminerId"