简体   繁体   English

如何在解决方案资源管理器中合并我的代码隐藏文件?

[英]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!谢谢!

At first glance, your file names do look correct, so make sure that File Nesting is turned on in the Solution Explorer:乍一看,您的文件名确实正确,因此请确保在解决方案资源管理器中打开文件嵌套:

在此处输入图片说明

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

在此处输入图片说明 FileName.razor.cs文件名.razor.cs

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何访问 xamarin.android 中的文件。 还有在 Visual Studio 解决方案资源管理器中,我应该将文件放在哪里以便在我的代码中找到它 - how to access files in xamarin.android. And also in Visual Studio Solution explorer where should i place the file in order to locate it in my code 如何从文件后面的代码中打印我的标记中的值 - How do i print a value in my markup from the code behind file 意外删除了Xaml文件背后的代码。 如何再次添加代码? - Accidentally deleted the code behind for an Xaml file. How do I add the code behind again? 在解决方案资源管理器中选择命令时,如何知道选择了哪个文件 - How do I know what file was selected when the command was selected in the Solution Explorer 如何在文件后面的C#代码中访问从内容模板中的文本框输入的文本? - How do I go about accessing the text input from a textbox within a content template in my C# code behind file? 如何从我的代码后面传递一个非常长的字符串到我的javascript函数? - How do I pass a very long string to my javascript function from my code behind? 如何将XAML视图文件与其后面的代码重新连接? - How do I reconnect a XAML view file with it's code behind file? 如何从我的 aspx 页面将参数传递到 C# 代码隐藏方法? - How do I pass a parameter into a C# code-behind method from my aspx page? 如何在后面的代码中创建HTML文档并将其加载到WPF浏览器中 - How do I create an HTML document in my code behind and load it into a WPF browser 如何在我的代码后面的表中添加数据并以html显示? - How do I add data to a table in my code behind and display in html?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM