2014-04-07 90 views
0

是否有辦法在剃刀中動態創建html並動態添加類?這是我到目前爲止,但類在瀏覽器中回來空。如何將動態類添加到Html.Raw?

var tdClass = (i % 2 == 0) ? "" : "alternate_row"; 

@Html.Raw("<tr class='"+tdClass+"'>") 
+0

是與在那裏額外的單引號一個錯字? – Danny

+0

如果您想要設置交替行的樣式,您可以使用css本身。 'tr:nth-​​child(奇怪)','tr:nth-​​child(偶數)'http://caniuse.com/#search=nth-child – PSL

+0

是的,已更新,但仍無法解決問題。 – Rayshawn

回答

0

看起來你是在類名後缺少關閉單引號「'」:

@Html.Raw("<tr class='"+tdClass+"'>")