另一个项目不起作用的视图组件

发布于 2025-02-12 12:45:50 字数 1245 浏览 1 评论 0原文

我正在使用ASP.NET Core 5.0用于正在使用ViewComponents的Web应用程序。 另一个项目中定义了视图组件类。 主要项目的观点太多,因此我补充说:

<PropertyGroup>
  <RazorCompileOnBuild>false</RazorCompileOnBuild>
  <RazorCompileOnPublish>true</RazorCompileOnPublish>
</PropertyGroup>

在.csproj文件中,将编译时间从120秒减少到10。但是,我遇到了问题。在我的主要项目中不再检测到视图组件。它们没有出现在查看结果中,甚至没有由Intellisense提出。
视图组件:

[ViewComponent(Name = "EntityForm")]
public class EntityFormViewComponent : ViewComponent
{
    public async Task<IViewComponentResult> InvokeAsync()
    {
        if (ViewData.ContainsKey("ViewMode") && ((ViewMode)ViewData["ViewMode"] == ViewMode.Create || (ViewMode)ViewData["ViewMode"] == ViewMode.Edit || (ViewMode)ViewData["ViewMode"] == ViewMode.Delete))
            return View("EntityForm");
        else
            return View("EntityGrid");
    }
}

项目层次结构:

图像中显示的视图组件都没有razorcompileonbuild设置为false
查看组件用法:

<vc:entity-form />

I'm using ASP.Net Core 5.0 for a web application in which I'm using ViewComponents. The ViewComponent classes are defined in another project. The main project has too many views so I added:

<PropertyGroup>
  <RazorCompileOnBuild>false</RazorCompileOnBuild>
  <RazorCompileOnPublish>true</RazorCompileOnPublish>
</PropertyGroup>

in the .csproj file, reducing the compile time from 120 seconds to 10. But then I faced a problem. The ViewComponents are not detected anymore in my main project. They don't appear in view results and even not suggested by intellisense.
The ViewComponent:

[ViewComponent(Name = "EntityForm")]
public class EntityFormViewComponent : ViewComponent
{
    public async Task<IViewComponentResult> InvokeAsync()
    {
        if (ViewData.ContainsKey("ViewMode") && ((ViewMode)ViewData["ViewMode"] == ViewMode.Create || (ViewMode)ViewData["ViewMode"] == ViewMode.Edit || (ViewMode)ViewData["ViewMode"] == ViewMode.Delete))
            return View("EntityForm");
        else
            return View("EntityGrid");
    }
}

The project hierarchy:
enter image description here

None of the ViewComponents shown in the image work with RazorCompileOnBuild set to false.
ViewComponent usage:

<vc:entity-form />

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文