System.NullReferenceException Message=Object reference not set to an instance of an object.

Mertix 21 Reputation points
2022-07-21T12:50:29.983+00:00

I want the club's name to be written in the Club ID section, but I am getting this error. There was no problem with the class names. It shows "A-B OR C" but the club didn't work
223068-screenshot-2022-07-21-141100.png223139-screenshot-2022-07-21-152452.png223140-screenshot-2022-07-21-154731.png

Developer technologies ASP.NET ASP.NET Core
SQL Server Other
0 comments No comments
{count} votes

Accepted answer
  1. Naomi Nosonovsky 8,431 Reputation points
    2022-07-21T13:20:13.217+00:00

    In your foreach loop in the code the last line

    <td>(@std.TBCLUB?.ClubName??"")</td> (this should work in C# 6.0) I just looked up this https://www.informit.com/articles/article.aspx?p=2421572

    If your version is prior, I think you need to construct the expression a bit more complex using @if @Else inside foreach

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Naomi Nosonovsky 8,431 Reputation points
    2022-07-21T12:57:34.227+00:00

    Can you safeguard in the code directly using ?? operator ? What exactly you're using?


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.