Hi I am using C# razor with umbraco cms. I am trying to check if a variable is null or empty but it always returns an error. Here is the code
@if(String.IsNullOrEmpty(@Model.originalPageLink) == false)
{
<div>Read the original page from <a href="@Model.originalPageLink">@Model.originalPageName</a></div>
}
When loading the page the razor script errors out. There is no particular error information that is useful. The part of the code thats giving me problems is this:
@if(String.IsNullOrEmpty(Model.originalPageLink) == false)
I have tried this code here:
@if(Model.originalPageLink != null)
This code does not error o开发者_开发知识库ut but returns a non null value when the string is really null.
Any ideas on this?
OK..I have figured it out.. Here is the solution
@if(String.IsNullOrEmpty(@Model.originalPageLink.ToString()) == false )
I have to put ToString() on the dynamic variable. Now it works correctly now.
"when you have eliminated the impossible, whatever remains, however improbable, must be the truth"
Is it possible that Model is null? That is the only thing left that can possible be null...
精彩评论