【问题标题】:How can I change the view path for a View Component in ASP.NET Core?如何在 ASP.NET Core 中更改视图组件的视图路径?
【发布时间】:2019-12-12 11:29:46
【问题描述】:

我想实现如下结构的视图组件。

ViewComponents
-> Modal
---> ModalViewComponent.cs
---> Modal1ViewComponent.cs
---> Modal2ViewComponent.cs

我的视图结构

 Shared
 -> Components
 ---> Modal
 ------> Modal.cshtml
 ------> Modal1.cshtml
 ------> Modal2.cshtml

ModalViewComponent 是我的基本视图组件,我从中调用基于相同模型的其他视图组件。

我想将我所有的模态视图放在Modal 文件夹中,派生视图组件解析为具有相同名称的视图。

【问题讨论】:

    标签: asp.net-core asp.net-core-viewcomponent


    【解决方案1】:

    您可能知道,教科书的解决方案通常是实现IViewLocationExpander,您的ExpandViewLocations() 解析Type.Namespace property 以动态扩展搜索位置。这很容易实现。

    不幸的是,ASP.NET Core 3.x 中的there's a limitation(我会说是一个错误)无法为视图组件提供这些扩展器。 ASP.NET Core 团队意识到了这个限制,最初是hoping to squeeze a fix into ASP.NET Core 3.1。此功能后来推迟到 ASP.NET Core 5.0,但也没有实现。

    从那时起,Microsoft has closed this issue,并表示他们不会修复此问题。

    如果没有这种支持,很遗憾,这不是您可以(轻松)改变的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-30
      • 2021-05-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多