Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add non breaking space within razor helper method

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)
                {
                    &nbsp; @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

like image 493
levelnis Avatar asked Jan 25 '13 15:01

levelnis


People also ask

How do you code a non breaking space?

The &nbsp; character entity prevents this from happening. When you insert the &nbsp; character between such words, it will render a space and will never let any of the words break into a new line.

What is directive in razor?

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.


1 Answers

Add @: before your non-breaking space html code

like image 76
pierrehenri56 Avatar answered Oct 27 '22 21:10

pierrehenri56