Following this guide, I\'m trying to show on an ASP.NET Core 2.0 page the settings values.
In startup.cs I added some services:
services.AddLocalizat
The answer is here:
The @page Razor directive makes the file into an MVC action — which means that it can handle requests. @page must be the first Razor directive on a page.
Hence the solution is extremely simple, just reorder the directives:
@page
@using Microsoft.Extensions.Options
@inject IOptions<MyOptions> Options
@model AboutModel
@{
ViewData["Title"] = "About";
}
<
<h3>@Model.Message</h3>
<br />
<div>
<h3>Options</h3>
<p><b>Refresh time</b> @Options.Value.SubOpt.RefreshTime</p>
</div>
you still need to add the below code in your startup.cs file
services.AddLocalization(options => options.ResourcesPath = "Resources");
services.AddOptions();
services.Configure<MyOptions>(Configuration);
also you need to set the default value of RefreshTime in appsettings.json and then use the below code in.cshtml page
@using Microsoft.Extensions.Options;
@using <enter the namespace for your MyOptions class here>;
@inject IOptions<MyOptions> Options
@page
@model AboutModel
@{
ViewData["Title"] = "About";
}
<
<h3>@Model.Message</h3>
<br />
<div>
<h3>Options</h3>
<h4>Sub Options</h4>
<p><b>Refresh time</b> @Options.Value.SubOpt.RefreshTime</p>
</div>
let me know if it works for you.