@{
@inject IConfiguration configuration
// This injects the IConfiguration service directly into the view making configuration settings (appsettings.json)
// accessible without controller dependencies. IConfiguration service may also be injected to the controllers.
// configuration is the local variable name that will be used in this view such as to reach the Title section
// of appsettings.json, configuration["Title"] will be used as below.
}
@{
/*
ViewData and ViewBag are the same collection (dictionary).
They carry extra data other than the model object from a controller action to its view, or between views.
The value assigned will be shown in Views/Shared/_Layout.cshtml view's title tag of the head tag.
*/
// Way 1:
// ViewData["Title"] = "Home Page";
// Way 2:
ViewBag.Title = "Home Page";
}
<div class="text-center">
<h1 class="display-4">Welcome to @configuration["Title"]</h1>
@* Changed from <h1 class="display-4">Welcome to Products MVC</h1> to use Title in appsettings.json *@
</div>
@* Added to show App section's Version and Date values in appsettings.json: *@
<p class="text-center">
Version: @configuration["App:Version"]
<br />
Date: @configuration["App:Date"]
</p>