'Is it possible to simplify this if statement?

Here's the code. Is it possible to one-line this code? I know of the (()?:) format, but not sure how to do this in Blazor.

<td>
  @if (piece.PublisherId == null)
  {
    @((MarkupString)$"<i>empty</i>")
  }
  else
  {
    @piece.Publisher.Name
  }
</td>


Solution 1:[1]

In addition to @Henk Holterman's answer:

Using the ?:;

@((MarkupString)(piece.PublisherId is null ? "<i>Empty</i>" : $"{piece.PublisherId}"))

Personally I like to keep my markup code as clean as possible so I would do something like this:

@page "/"

<PageTitle>Index</PageTitle>
<div class="p2">
    DATA : @this.GetDataDiplay(null)
</div>

@code {
    private MarkupString GetDataDiplay(int? value) 
        => new MarkupString(value is null 
            ? "<i>Empty</i>" 
            : $"{value}");
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 MrC aka Shaun Curtis