@@ -180,20 +180,28 @@ In this example, you'll update a web page to display its content using the setti
180
180
181
181
---
182
182
183
- 1. Open *Index.cshtml.cs* in the *Pages* directory and update it with the following code. Add the `using Microsoft.Extensions.Options` namespace.
183
+ 1. Open *Index.cshtml.cs* in the *Pages* directory and update the file:
184
+
185
+ 1. Add the `using Microsoft.Extensions.Options` namespace.
186
+ 1. Update the `IndexModel` class.
187
+
188
+ #### [.NET 6.x](#tab/core6x)
184
189
185
190
```csharp
186
191
using Microsoft.AspNetCore.Mvc.RazorPages;
192
+
193
+ // Add using Microsoft.Extensions.Options;
187
194
using Microsoft.Extensions.Options;
188
195
189
196
namespace TestAppConfig.Pages;
190
197
198
+ // Update the IndexModel class
191
199
public class IndexModel : PageModel
192
200
{
193
201
private readonly ILogger<IndexModel> _logger;
194
-
202
+
195
203
public Settings Settings { get; }
196
-
204
+
197
205
public IndexModel(IOptionsSnapshot<Settings> options, ILogger<IndexModel> logger)
198
206
{
199
207
Settings = options.Value;
@@ -202,6 +210,41 @@ In this example, you'll update a web page to display its content using the setti
202
210
}
203
211
```
204
212
213
+ #### [.NET Core 3.x](#tab/core3x)
214
+
215
+ ```csharp
216
+ using System;
217
+ using System.Collections.Generic;
218
+ using System.Linq;
219
+ using System.Threading.Tasks;
220
+ using Microsoft.AspNetCore.Mvc;
221
+ using Microsoft.AspNetCore.Mvc.RazorPages;
222
+ using Microsoft.Extensions.Logging;
223
+
224
+ // Add using Microsoft.Extensions.Options;
225
+ using Microsoft.Extensions.Options;
226
+
227
+ namespace TestAppConfig.Pages
228
+
229
+ // Update the IndexModel class
230
+ {
231
+ public class IndexModel : PageModel
232
+ {
233
+ private readonly ILogger<IndexModel> _logger;
234
+
235
+ public Settings Settings { get; }
236
+
237
+ public IndexModel(IOptionsSnapshot<Settings> options, ILogger<IndexModel> logger)
238
+ {
239
+ Settings = options. Value;
240
+ _logger = logger;
241
+ }
242
+ }
243
+ }
244
+ ```
245
+
246
+ ---
247
+
205
248
1. Open *Index.cshtml* in the *Pages* directory, and update the content with the following code.
206
249
207
250
```html
0 commit comments