Warning CS8618 Non-nullable property 'Categories_List' must contain a non-null value when exiting constructor. Consider declaring the property as nullable. RazorPageDemoYoutube D:\ASP.NET\RazorPage\RazorPageDemo\RazorPageDemoYoutube\Pages\Admin\Categories\Index.cshtml.cs 16 Active
Asked
Active
Viewed 58 times
1

Qing Guo
- 6,041
- 1
- 2
- 10

Amila Praneeth
- 11
- 1
-
In constructor just do Categories_List= new List
– D A May 19 '23 at 05:38 -
You can use the `?` suffix to declare a nullable reference type. Try to add `?` ,like `public IEnumerable
? Categories_List { get; set; }` . – Qing Guo May 19 '23 at 05:39 -
The Warning includes the answer to your question How to fix: *Consider declaring the property as nullable.* – Sir Rufo May 19 '23 at 05:51
1 Answers
0
Try to add ?
,like :
public IEnumerable<Category>? Categories_List { get; set; }
OR:
public IEnumerable<Category> Categories_List { get; set; } = new List<Category>();

Qing Guo
- 6,041
- 1
- 2
- 10
-
@Amila Praneeth I use this way to avoid this warning. Is your problem solved ? – Qing Guo May 19 '23 at 05:46