We help IT Professionals succeed at work.
Get Started
Troubleshooting Question

How I can handle System.NullReferenceException error?

Last Modified: 2020-10-05

I'm getting this error:

System.NullReferenceException: 'Object reference not set to an instance of an object.'

@if (Model.Environment.ToString() != " " || !String.IsNullOrEmpty(Model.Environment.ToString())
        || Model.Environment.ToString() != null)
                            @Html.LabelForModel(Model.Environment, new { @style = "font-weight:normal;font-size:12px;" })
my value for Model.Environment is null
I want to say if it is not null then do the @Html.LabelForModel

I have tried everything I can think of but it's not working

Thank you in advance for your help.

Watch Question
Distinguished Expert 2019
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE