C# 如何修复Blazor中的转换数据模型

C# 如何修复Blazor中的转换数据模型,c#,blazor-server-side,C#,Blazor Server Side,我在尝试将数据加载到blazor组件时遇到以下错误 Error CS0029 Cannot implicitly convert type 'System.Collections.Generic.List<Gars.DataModels.Picks>' to 'System.Collections.Generic.List<GarsApp.Pages.Picks>' 在应用程序中的某个地方,存在一个名为Picks的类,该类被定义为属于GapsApp.Pages命名

我在尝试将数据加载到blazor组件时遇到以下错误

Error   CS0029  Cannot implicitly convert type 'System.Collections.Generic.List<Gars.DataModels.Picks>' to 'System.Collections.Generic.List<GarsApp.Pages.Picks>'

在应用程序中的某个地方,存在一个名为
Picks
的类,该类被定义为属于
GapsApp.Pages
命名空间。也许它在另一个装配中,但它肯定在那里。并且它与
LoadPicks
方法返回的类型不匹配,因此出现错误

因此,当您声明
\u currentPicks
时,您需要指定所需的确切类型,这样就不会产生混淆

e、 g

List_currentPicks=newlist();

“世上没有像GarsApp.Pages.Picks这样的东西”……一定有。软件没有骗你。如果您使用的是visual studio,则可以将鼠标悬停在代码中的
Picks
类型上,它将告诉您名称空间。您也可以右键单击它并转到该类。在页面顶部或Imports.razor中是否有任何使用语句的
,这些语句可能引用相关命名空间?添加了无法导航到该类的图像。好的,在您的应用程序中,该类存在并被定义为属于GapsApp.Pages命名空间。也许在另一个集会上,但它肯定在那里。而且它与
LoadPicks
返回的类型不匹配。因此,当您声明
\u currentPicks
时,您需要指定所需的确切类型,这样就不会产生混淆。e、 g.
List_currentPicks=新列表()@ADyson我在声明中加入了完整的路径,它现在正在工作。不知何故,在某个地方有一个我不想要的班级。谢谢你的帮助。
@code {
private List<GameData> _gameData = new List<GameData>();
private int _currentWeek;
private List<Picks> _currentPicks = new List<Picks>();



protected override async Task OnInitializedAsync()
{
    var authSate = await AuthenticationStateProvider.GetAuthenticationStateAsync();
    var user = authSate.User;


    _gameData = await gameRepo.GetCurrentGames();
    _currentWeek = await gameRepo.GetCurrentWeek();

    // _currentPicks = _db.Picks.Where(x => x.UserId == user.Identity.Name && x.Week == _currentWeek).ToList<Picks>();

    _currentPicks = await pickRepo.LoadPicks(user.Identity.Name, _currentWeek);


}
@using Gars.DataModels;
@using GarsApp.Repsositories;
@using Microsoft.AspNetCore.Identity
@using Microsoft.AspNetCore.Components.Authorization
 
@inject AuthenticationStateProvider AuthenticationStateProvider

@inject GameDataRepo gameRepo
@inject PickRepo pickRepo
@inject ApplicationDbContext _db
 
List<Gars.DataModels.Picks> _currentPicks = new List<Gars.DataModels.Picks>();