另一个项目不起作用的视图组件
我正在使用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");
}
}
None of the ViewComponents shown in the image work with RazorCompileOnBuild
set to false
.
ViewComponent usage:
<vc:entity-form />
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论