You can check the following: -
@if(Model != null && Model.TagsList != null) //NUll check for Model { foreach (string tag in Model.TagsList) { <li>@tag</li> } }
You do not need to check whether the TagsList values TagsList or not (if they are initialized), if the List empty, it will not throw any errors and will not enter the loop.
source share