我定义了一个具有特定主题设置的设置类--在本例中是站点的主标题:
public class ThemeSettings : IConfigurationSettings
{
[Required]
public string SiteTitle { get; set; }
}现在我想将站点标题包含在我的_Layout.cshtml文件中:
_Layout.cshtml:
<h2 class="header-title"> ... INSERT TITLE HERE ... </h2>但是,如何在没有控制器的情况下将ThemeSettings类注入视图文件,以便可以访问属性SiteTitle
发布于 2021-03-04 08:18:07
在ASP.NET核心中支持依赖注入的剃刀文件:
@inject ThemeSettings themeSettings
<h2 class="header-title">@themeSettings.SiteTitle</h2>https://stackoverflow.com/questions/66470729
复制相似问题