Answered by:
Mix text and funtion inside a If statement

Question
-
User982203039 posted
How can I add text ( - ) in front of the ticket.Phone. So I want the display to be - 555-5555 instead of 555-5555.
<td>@ticket.RequestedBy @if (ticket.Phone != null) { @ticket.Phone}</td>
Thanks,
EB
Wednesday, October 16, 2019 10:03 PM
Answers
-
User475983607 posted
Use HTML.
<td> @ticket.RequestedBy @if (ticket.Phone != null) { <span>-</span> @ticket.Phone } </td>
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, October 16, 2019 10:43 PM -
User-17257777 posted
Hi Baze72,
the - shows up even if Ticket.Phone is null.What does the "null" mean? Ticket.Phone = null or Ticket.Phone = "" ? For these two conditions, you can use string.IsNullOrEmpty().
<td> @ticket.RequestedBy @if (!string.IsNullOrEmpty(ticket.Phone)) { <span>-</span> @ticket.Phone } </td>
If this is not the case, could you please show us an example?
Best Regards,
Jiadong Meng
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, October 17, 2019 9:06 AM
All replies
-
User475983607 posted
Use HTML.
<td> @ticket.RequestedBy @if (ticket.Phone != null) { <span>-</span> @ticket.Phone } </td>
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, October 16, 2019 10:43 PM -
User982203039 posted
mgebhard
Use HTML.
<td> @ticket.RequestedBy @if (ticket.Phone != null) { <span>-</span> @ticket.Phone } </td>
I figured it would be easy!
one quick question: the - shows up even if Ticket.Phone is null. Why would that be?
Thursday, October 17, 2019 1:48 AM -
User-17257777 posted
Hi Baze72,
the - shows up even if Ticket.Phone is null.What does the "null" mean? Ticket.Phone = null or Ticket.Phone = "" ? For these two conditions, you can use string.IsNullOrEmpty().
<td> @ticket.RequestedBy @if (!string.IsNullOrEmpty(ticket.Phone)) { <span>-</span> @ticket.Phone } </td>
If this is not the case, could you please show us an example?
Best Regards,
Jiadong Meng
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, October 17, 2019 9:06 AM