How can I include a non-breaking space (
) within a Razor helper method? Here's the helper in question:
@helper RenderClipResult(Clip clip, IList<string> searchTerms)
{
<div class="result">
<!-- other clip stuff -->
@if (clip.ThirdPartyMaterials != null && clip.ThirdPartyMaterials.Count > 0)
{
<p>
<span class="heading">Third Party Material</span><br/>
@foreach (var material in clip.ThirdPartyMaterials)
{
@AddElement("Description", material.Description, searchTerms) @AddElement("Cost", material.Cost, searchTerms)
<br />
}
</p>
}
</div>
}
AddElement
is another custom helper. The output I'm looking for is something like this:
Third Party Material
first entry
second entry
third entry
I could wrap the AddElement
line in a span tag for styling but it's another html tag and css rule, just to indent some text by a single character width. Might have to go that way as Razor is not able to parse the space
The character entity prevents this from happening. When you insert the character between such words, it will render a space and will never let any of the words break into a new line.
Razor directives are represented by implicit expressions with reserved keywords following the @ symbol. A directive typically changes the way a view is parsed or enables different functionality. Understanding how Razor generates code for a view makes it easier to understand how directives work. CSHTML Copy.
Add @:
before your non-breaking space html code
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With