Run*_*ney 3 c# blazor blazor-server-side .net-core-3.1
我正在尝试为我的 blazor 应用程序创建一个代码隐藏文件(使用 .NET Core 3.1,Blazor 服务器端),同时它也会在解决方案资源管理器中显示为 razor 文件,您可以单击“打开”,然后查看树形结构中的 razor.cs 文件。
我设法使功能正常工作,但它仍然没有在解决方案资源管理器中正确显示。
据我所知,我做的一切都是正确的,我什至尝试使用项目模板,但这也不起作用。无论我尝试什么,它们总是显示为单独的文件。
文件名是相同的,除了扩展名之外,该类继承自ComponentBase,我尝试过在文件FetchData或FetchDataBase中调用该类,都不起作用。
我的类文件名为:“FetchData.razor.cs” 我的剃刀文件名为“FetchData.razor”
我错过了什么吗?我使用的是 VS2019 V16.5.2,我需要使用预览版吗?
代码片段: 类:
public partial class FetchDataBase : ComponentBase
{
[Inject]
private CoordinatesService CoordinatesService { get; set; }
protected IEnumerable<ICoordinate> coordinates;
protected override async Task OnInitializedAsync()
{
coordinates = await CoordinatesService.GetCoordinates();
}
}
Run Code Online (Sandbox Code Playgroud)
剃须刀页面:
@page "/fetchdata"
@inherits FetchDataBase
<h1>Coordinates</h1>
<p>This component demonstrates fetching data from a service.</p>
@if (coordinates == null)
{
<p><em>Loading...</em></p>
}
else
{
<table class="table">
<thead>
<tr>
<th>Test</th>
</tr>
</thead>
<tbody>
@foreach (var coordinate in coordinates)
{
<tr>
<td>@coordinate.Test</td>
</tr>
}
</tbody>
</table>
}
Run Code Online (Sandbox Code Playgroud)
解决方案资源管理器的图像:
谢谢!