Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access Configuration from a View in ASP.NET Core

Tags:

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> 
like image 917
spottedmahn Avatar asked Nov 14 '17 22:11

spottedmahn


People also ask

What is the use of IConfiguration in .NET Core?

The IConfiguration is an interface for . Net Core 2.0. The IConfiguration interface need to be injected as dependency in the Controller and then later used throughout the Controller. The IConfiguration interface is used to read Settings and Connection Strings from AppSettings.


1 Answers

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"> 
like image 161
Shyju Avatar answered Oct 10 '22 10:10

Shyju