我有一個包含大約 60 個不同多邊形的 SVG,我需要根據傳入的溫度值更改顏色,但 Html.Raw 沒有在編譯時插入我需要的文本。
這就是我的觀點。
<svg id="_mapa" class="dragger" xmlns="http://www.w3.org/2000/svg">
<polygon class="polyArea"
onclick="window.location.href='@Url.Action("Red","Home")'"
name="13" points="1345,955 1345,1080 1875,1080 1875,1015 1935,1015 1935,955"
stroke="black" stroke-width="5"
@if ((int)ViewBag.Thirteen >= 100) { Html.Raw("fill='#E74C3C'"); } //red
else if ((int)ViewBag.Thirteen > 80 && (int)ViewBag.Thirteen < 100) { Html.Raw("fill='#F4D03F'"); } //yellow
else { Html.Raw("fill='#2ECC71'"); }
opacity="0.5" style="cursor: pointer;">
<title>Cuiseur a Vapeur Current Temperature: @ViewBag.Thirteen °F</title>
</polygon>
</svg>
但這就是它在實際頁面上回傳的內容。
<svg id="_mapa" class="dragger" xmlns="http://www.w3.org/2000/svg">
<polygon class="polyArea" name="13"
onclick="window.location.href='/Home/Red'"
points="1345,955 1345,1080 1875,1080 1875,1015 1935,1015 1935,955" stroke="black"
stroke-width="5" opacity="0.5" style="cursor: pointer;">
<title>Cuiseur a Vapeur
Current Temperature: 135 °F</title></polygon>
</svg>
如您所見,填充屬性根本沒有被插入,這甚至可能嗎?
uj5u.com熱心網友回復:
在我的桌子上敲了一會兒后,我想通了:
<svg id="_mapa" class="dragger" xmlns="http://www.w3.org/2000/svg">
<polygon class="polyArea"
onclick="window.location.href='@Url.Action("Red","Home")'"
name="13" points="1345,955 1345,1080 1875,1080 1875,1015 1935,1015 1935,955"
stroke="black" stroke-width="5"
@if ((int)ViewBag.Thirteen >= 100) { @Html.Raw("fill='#E74C3C'"); } //red
else if ((int)ViewBag.Thirteen > 80 && (int)ViewBag.Thirteen < 100) { @Html.Raw("fill='#F4D03F'"); } //yellow
else { @Html.Raw("fill='#2ECC71'"); }
opacity="0.5" style="cursor: pointer;">
<title>Cuiseur a Vapeur Current Temperature: @ViewBag.Thirteen °F</title>
</polygon>
</svg>
我在 if 陳述句中的 Html.Raw 之前缺少“@”。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/443830.html
標籤:html asp.net-mvc 剃刀
