Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I have a rich text area called "preferredExperience" and I only want to show it if it has data.
I tried
@if (@Model.Value("preferredExperience") != null) { <h1>Preferred Experience</h1> <p>@Model.Value("preferredExperience")</p> }
and
@if (!string.IsNullOrWhiteSpace(@Model.Value("preferredExperience"))) { <h1>Preferred Experience</h1> <p>@Model.Value("preferredExperience")</p> }
but the title (H1) is always showing.. Can someone tell me what is the correct way to check for empty/Null?
Hi Yaco
Does
@if (Model.HasValue("preferredExperience")) { <h1>Preferred Experience</h1> <p>@Model.Value("preferredExperience")</p> }
Give what you need?
Regards
Marc
Hi Yaco,
Can you try this.
var text = Model.Value<IHtmlEncodedString>("preferredExperience"); var hasText = text != null && !string.IsNullOrWhiteSpace(text.ToString())); if(hasText) { <h1>Preferred Experience</h1> @text }
Dave
I tested @if (Model.HasValue("preferredExperience")) and it worked well.
Thank you both
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
How do I check if a richtext area is empty?
I have a rich text area called "preferredExperience" and I only want to show it if it has data.
I tried
and
but the title (H1) is always showing.. Can someone tell me what is the correct way to check for empty/Null?
Hi Yaco
Does
Give what you need?
Regards
Marc
Hi Yaco,
Can you try this.
Dave
I tested @if (Model.HasValue("preferredExperience")) and it worked well.
Thank you both
is working on a reply...