lulu50
asked on
How I can handle System.NullReferenceException error?
Hello,
I'm getting this error:
System.NullReferenceException: 'Object reference not set to an instance of an object.'
and
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.
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 and
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
@if (!string.IsNullOrWhiteSpace(Model.Environment))
The model is always valid (!= null) because it is a Razor page.