Reputation: 16011
How can I access IConfiguration
in an MVC View in ASP.NET Core 1.1?
Ex. _Layout.cshtml
<link href="@Configuration["MyConfigEntry"]/css/site.min.css>
Upvotes: 33
Views: 12521
Reputation: 3382
@inject
it into the view (if that's really what you want to do).
Additional documentation: Options provided by a view model or with direct view injection
Upvotes: 11
Reputation: 218832
In asp.net core , you can inject IConfiguration
implementation to your views and use that :)
@using Microsoft.Extensions.Configuration
@inject IConfiguration Configuration
<link rel="stylesheet" href="@Configuration["MyConfigEntry"]/css/site.min.css">
Upvotes: 71
Reputation: 12196
If the posted link is where you took your example, then Probably by doing
<link href="@Startup.Configuration["MyConfigEntry"]/css/site.min.css>
This is because you set the Configuration object as static while bootstrap the application.
From Configure an ASP.NET Core App
public static IConfigurationRoot Configuration { get; set; }
Upvotes: 3