Note that there are some explanatory texts on larger screens.

plurals
  1. POHTML Parsing in Razor Helpers
    primarykey
    data
    text
    <p>I've got the following code,</p> <pre><code>@helper Category(IGroup group) { if (!group.Exist) { return; } var colors = AppContext.Settings.Colors.Charts.Net; var css = group.Name.Replace(" ", String.Empty).ToLower(); var id = css.ToUpper() + "_"; &lt;tr&gt; &lt;td class="summarygridbackground" style="font-weight:bold;"&gt;@group.Name&lt;/td&gt; &lt;/tr&gt; foreach(var category in group.Categories) { &lt;tr id="@id@category.Id" class="summarygridbackground"&gt; &lt;td class="category"&gt; &lt;div style="float:left"&gt;@category.Name&lt;/div&gt; &lt;div class="hovericon"&gt;@FormatAs.Currency(category.TotalValue)&lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; } &lt;tr class="summarygridbackground"&gt; @switch(css) { case "inv": &lt;text&gt; &lt;td class ="@css" style="color: @colors.Inv.html"&gt; &lt;/text&gt; break; case "other": &lt;text&gt; &lt;td class ="@css" style="color: @colors.Other.html"&gt; &lt;/text&gt; break; case "lib": &lt;text&gt; &lt;td class ="@css" style="color: @colors.Lib.html"&gt; &lt;/text&gt; break; case "net": &lt;text&gt; &lt;td class ="@css" style="color: @colors.Net.html"&gt; &lt;/text&gt; break; default: &lt;text&gt; &lt;td class="@css"&gt; &lt;/text&gt; break; } &lt;div style="float:left; padding-left:12px;"&gt; Total @group.Name&lt;/div&gt; &lt;div style="float:right; padding-right:10px;"&gt;@FormatAs.Currency(group.TotalValue)&lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; } </code></pre> <p>As it stands, the code fails on the last line of the helper when I load the view, with the following message:</p> <blockquote> <p>Parser Error Description: An error occurred during the parsing of a resource required to service this >request. Please review the following specific parse error details and modify your source >file appropriately.</p> <p>"Parser Error Message: Encountered end tag "tr" with no matching start tag. Are your start/end tags properly balanced?</p> <p>Source Error:</p> <p>Line 65: @FormatAs.Currency(group.TotalValue) Line 66: Line 67: Line 68: }"</p> </blockquote> <p>When I remove that last <code>&lt;/tr&gt;</code> on the last line, it fails with this message:</p> <blockquote> <p>Parser Error Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.</p> <p>Parser Error Message: The "tr" element was not closed. All elements must be either self-closing or have a matching end tag.</p> <p>Source Error:</p> <p>Line 32: Line 33: } Line 34: Line 35: @switch(css)</p> </blockquote> <p>I can't figure it out, that's the entire helper method, it looks balanced to me, and all calls to this helper both worked fine previously, and are not nested in <code>&lt;tr&gt;</code>s, only <code>&lt;div&gt;</code>s</p> <p>Could someone please help me?</p> <p>Edit: I managed to make it work by removing the <code>switch</code> from that segment, and instead using it at the beginning of the <code>foreach</code> to set a <code>var color</code>, and using that instead. This seems like it's a better solution anyway, but I'd still like to understand <em>why</em> it is that the first attempt didn't work.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload