我有下面的代碼,HTML語法分析剃刀助手
@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() + "_";
<tr>
<td class="summarygridbackground" style="font-weight:bold;">@group.Name</td>
</tr>
foreach(var category in group.Categories)
{
<tr id="@[email protected]" class="summarygridbackground">
<td class="category">
<div style="float:left">@category.Name</div>
<div class="hovericon">@FormatAs.Currency(category.TotalValue)</div>
</td>
</tr>
}
<tr class="summarygridbackground">
@switch(css)
{
case "inv":
<text>
<td class ="@css" style="color: @colors.Inv.html">
</text>
break;
case "other":
<text>
<td class ="@css" style="color: @colors.Other.html">
</text>
break;
case "lib":
<text>
<td class ="@css" style="color: @colors.Lib.html">
</text>
break;
case "net":
<text>
<td class ="@css" style="color: @colors.Net.html">
</text>
break;
default:
<text>
<td class="@css">
</text>
break;
}
<div style="float:left; padding-left:12px;"> Total @group.Name</div>
<div style="float:right; padding-right:10px;">@FormatAs.Currency(group.TotalValue)</div>
</td>
</tr>
}
因爲它的立場,代碼助手中的最後一行失敗,當我加載視圖,並顯示以下消息:
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.
"Parser Error Message: Encountered end tag "tr" with no matching start tag. Are your start/end tags properly balanced?
Source Error:
Line 65: @FormatAs.Currency(group.TotalValue) Line 66: Line 67: Line 68: }"
當我刪除,去年</tr>
最後一行時,出現此消息:
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.
Parser Error Message: The "tr" element was not closed. All elements must be either self-closing or have a matching end tag.
Source Error:
Line 32: Line 33: } Line 34: Line 35: @switch(css)
我不能算起來,這就是整個的輔助方法,它看起來平衡對我來說,和這個幫助所有電話都工作正常之前,而不是嵌套在<tr>
S,只有<div>
小號
有人能幫助我嗎?
編輯:我設法通過從該段中刪除switch
,而不是在foreach
的開頭使用它來設置var color
,並用它來代替。這似乎是一個更好的解決方案,但我仍然想了解爲什麼這是第一次嘗試不起作用。
-1。下次請努力做一下5-7行的樣品。如果你嘗試過這個問題,你會發現自己回答的機會也很大。 –
對不起,我問的最初幾個問題最終被要求在短時間內提供額外的上下文,所以我認爲這次我會給出一個合理的完整上下文。 – Sconibulus