Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Blazor WASM中的MudSelect问题_C#_Blazor_Blazor Webassembly - Fatal编程技术网

C# Blazor WASM中的MudSelect问题

C# Blazor WASM中的MudSelect问题,c#,blazor,blazor-webassembly,C#,Blazor,Blazor Webassembly,我是Blazor WASM的新手,我正在从事一个使用MudBlazor的项目。但是,我对MudSelect有一个问题。我想在MudSelect中显示部门名称。但是,我需要绑定部门ID。下面的代码部分起作用,但当我想编辑个人时,只显示部门ID。它不会转换为部门名称,但当我单击屏幕时,它会变成DepatmentName 我哪里做错了?提前谢谢 <MudSelect @bind-Value="personal.DepartmentID" Label="Select

我是Blazor WASM的新手,我正在从事一个使用MudBlazor的项目。但是,我对MudSelect有一个问题。我想在MudSelect中显示部门名称。但是,我需要绑定
部门ID
。下面的代码部分起作用,但当我想编辑个人时,只显示
部门ID
。它不会转换为部门名称,但当我单击屏幕时,它会变成
DepatmentName

我哪里做错了?提前谢谢

<MudSelect @bind-Value="personal.DepartmentID" Label="Select Department"  Variant="Variant.Outlined"  OffsetY="true">

    @foreach (var department in departments){
          <MudSelectItem  Value="@(department.DepartmentID)">@item.DepartmentName</MudSelectItem>
    }
</MudSelect>       

@foreach(部门中的var部门){
@item.DepartmentName
}
@代码段

@code{
     [Parameter] public List<Department> departments { get; set; } = new List<Department>();

      protected async override Task OnInitializedAsync()
      {
            departments = await departmentRepository.GetDepartment();
      }
}
@code{
[参数]公共列表部门{get;set;}=new List();
受保护的异步重写任务OnInitializedAsync()
{
departments=await departmentRepository.GetDepartment();
}
}
存储库

    public async Task<List<Department>> GetDepartment()
    {
        var response = await httpService.Get<List<Department>>(url);
        
        if (!response.Success)
        {
            throw new ApplicationException(await response.GetBody());
        }

        return response.Response;   
    }
公共异步任务GetDepartment() { var response=wait-httpService.Get(url); 如果(!response.Success) { 抛出新的ApplicationException(wait response.GetBody()); } 回应。回应; } 控制器

   [HttpGet]
    public async Task<ActionResult<List<Department>>> Get() 
    {
        return  await context.Departments.ToListAsync();
    }
[HttpGet]
公共异步任务Get()
{
返回wait context.Departments.toListSync();
}

您可以共享您的
@code
部分吗?您的代码显示显示
@item.DepartmentName
,但您的值引用了
@(department.DepartmentID)
。什么是
?当然,您应该显示
@department.DepartmentName