ASP.NET Core 2.0 read: Options in razor page

前端 未结 2 1437
南方客
南方客 2021-01-19 04:55

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         


        
2条回答
  •  梦毁少年i
    2021-01-19 05:25

    you still need to add the below code in your startup.cs file

    services.AddLocalization(options => options.ResourcesPath = "Resources");
    services.AddOptions();
    services.Configure(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 ;
    @inject IOptions Options
    @page
    @model AboutModel
    @{
        ViewData["Title"] = "About";
    }
    <
    

    @Model.Message


    Options

    Sub Options

    Refresh time @Options.Value.SubOpt.RefreshTime

    let me know if it works for you.

提交回复
热议问题