简体   繁体   English

我应该在我的 .NET 6 项目中混合 .cshtml 文件和 .razor 文件吗?

[英]Should I be mixing .cshtml files and .razor files in my .NET 6 project?

I'm not trying to specifically create a Blazor Web application, rather I'm rewriting an old ASP.Net Framework application in Razor and the newest .NET (currently .NET 6). I'm not trying to specifically create a Blazor Web application, rather I'm rewriting an old ASP.Net Framework application in Razor and the newest .NET (currently .NET 6). I've created a.razor component for my Footer that is going to appear in all of my pages.我为我的页脚创建了一个.razor 组件,该组件将出现在我的所有页面中。 I'm unable to get it to display, I currently have this:我无法让它显示,我目前有这个:

@section Footer {
    <component type="typeof(NewProject.Pages.Footer)" render-mode="Static"/>
}

But then I have read that.razor files are supposed to be used in Blazor Web applications and they should be used instead of.cshtml files.但后来我读到了。razor 文件应该在 Blazor Web 应用程序中使用,它们应该用来代替.cshtml 文件。 I'm trying to stick to Razor pages and MVVM instead of MVC, and I'm still very new to both Razor and Blazor, and before I get too much further into this, I would like to know if I should instead create the Footer as a Partial View instead of a Blazor component.我正在尝试坚持使用 Razor 页面和 MVVM 而不是 MVC,而且我对 Razor 和 Blazor 还是很陌生,如果我应该更深入地了解这个 Footer IZ作为局部视图,而不是 Blazor 组件。 These are the files I've created.这些是我创建的文件。

文件列表

Microsoft's answer, apparently, is a big yes.显然,微软的回答是肯定的。 The default Blazor project uses cshtml as the foundation for the site, as well as for the scaffolded Identity system, and razor for everything else.默认的 Blazor 项目使用 cshtml 作为站点的基础,以及脚手架的身份系统,razor 用于其他所有内容。

I know you're not planning to use Blazor, but the above indicates to me that they're meant to co-exist.我知道您不打算使用 Blazor,但以上内容向我表明它们应该共存。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM