ASP.NET Core 2.0 read: Options in razor page

前端 未结 2 1449
南方客
南方客 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:24

    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 Options
    @model AboutModel
    @{
        ViewData["Title"] = "About";
    }
    <
    

    @Model.Message


    Options

    Refresh time @Options.Value.SubOpt.RefreshTime

提交回复
热议问题