[英]How do I merge my code behind file in the solution explorer?
I am trying to create a code-behind file for my blazor application (Using .NET Core 3.1, Blazor-server-side), while it also shows up in the solution explorer as the razor file you can click open, and then see the razor.cs file in the tree structure.我正在尝试为我的 blazor 应用程序创建一个代码隐藏文件(使用 .NET Core 3.1,Blazor 服务器端),同时它也显示在解决方案资源管理器中作为您可以单击打开的 razor 文件,然后看到razor.cs 文件中的树结构。
I managed to get the funcionality to work, but it still doesn't show up correctly in the solution explorer.我设法使功能正常工作,但它仍然没有在解决方案资源管理器中正确显示。
As far as I know I am doing everything correctly, I even tried to use an item template, and that didn't work either.据我所知,我所做的一切都是正确的,我什至尝试使用项目模板,但这也不起作用。 Whatever I try, they always show up as seperate files.
无论我尝试什么,它们总是显示为单独的文件。
The file names are the same, except for the extension, the class inherits from ComponentBase, I have tried calling the class in the file FetchData or FetchDataBase, neither works.文件名相同,除了扩展名,类继承自ComponentBase,我尝试在文件FetchData或FetchDataBase中调用该类,都不起作用。
My class file is called: 'FetchData.razor.cs' My razor file is called 'FetchData.razor'我的类文件被称为:'FetchData.razor.cs' 我的剃刀文件被称为'FetchData.razor'
Am I missing something?我错过了什么吗? I am on VS2019 V16.5.2, do I need to be on the preview version for this?
我使用的是 VS2019 V16.5.2,我需要使用预览版吗?
Code snippets: class:代码片段: 类:
public partial class FetchDataBase : ComponentBase
{
[Inject]
private CoordinatesService CoordinatesService { get; set; }
protected IEnumerable<ICoordinate> coordinates;
protected override async Task OnInitializedAsync()
{
coordinates = await CoordinatesService.GetCoordinates();
}
}
razor page:剃须刀页面:
@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>
}
Image of solution explorer:解决方案资源管理器的图像:
Thanks!谢谢!
Edit: Your file names look correct.编辑:您的文件名看起来正确。 Have you tried closing Visual Studio and reopening?
您是否尝试过关闭 Visual Studio 并重新打开? What are the little locks by your files, is that source control?
你的文件的小锁是什么,是源代码控制吗?
As I change a file name, the files switch in solution explorer to become embedded in the file.当我更改文件名时,文件会在解决方案资源管理器中切换以嵌入到文件中。
Name your file:命名您的文件:
FileName.razor文件名.razor
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.