Let's
explore the relationship between this Razor Page and the Razor Page's
Page Model because typically it is the Page Model that will perform
data access and do all the hard work to put together the data that
the Razor Page will display .
Easy data
source that I can access right now is my application configuration. One of
the sources of configuration for this application is appsettings.json
So, for example, if I add a Message property to this JSON file and I
say that message is equal to Hello world from appsettings!.
let's say
I want to display this message in my Razor Page, well the whole idea in
the relationship between a Razor Page and its Page Model is that the
Razor Page is strictly about display.
So something I can do in ASP.NET Core is give my PageModel
a constructor, and my constructor can take a parameter of type
IConfiguration. We need to bring in the namespace
Microsoft.Extensions .Configuration.
Now add
model value in .cshtml page.
We just
press Enter and we can get value from the appsettings.json



Comments
Post a Comment