c# - 如何在子视图中使用剃刀布局视图中的注入服务
问题描述
刚刚了解在 asp.net core razor 视图中注入的服务。但是我还没有找到如何在子视图中使用在布局视图中注入的服务(将被许多视图使用)。
也许在概念上是这样的:
布局视图
@inject IOptions<PortalConfiguration> OptionsPortalConfiguration
<some HTLM markup>
@RenderBody(OptionsPortalConfiguration) <--pass it here???
子视图
Not sure how to reference it.
解决方案
这种情况的另一种方法是创建静态辅助方法,可以在所有视图中调用而无需注入。
public static class TestHelperExtensions
{
public static ITestProvider TestProvider { get; set; }
public static string Get(this ITestHelper html, string arg)
{
return TestProvider.Get(arg);
}
}
推荐阅读
- html - 使用 Internet Explorer 的 Html Google Fonts 字体在希伯来语中不起作用(适用于 Chrome 和 Firefox)
- node.js - 如何通过 Bale Bot 发送照片消息?
- c++ - 在 Google 测试中,我可以从构造函数中调用 GetParam() 吗?
- perl - 使用 LWP::Simple 时的状态 403
- voltdb - 如何在 voltDB 存储过程中声明变量
- hazelcast-jet - Hazelcast Jet 0.6.1 - Dag 定义
- unity3d - ARCore:在运行时禁用增强图像
- python - 存储过程没有错误,但不在 postgresql 中插入数据
- python - Cython 的多个输出文件有什么用?
- ios - Swift iOS - 使用 SegmentedControl 将 ChildViewController 添加到 CollectionView 部分