我想寫類似:如果使用HTML內容,我可以寫內聯嗎?
@(checkCondition ? "<span class='label'>Right!</span>" : "")
但它顯示的源代碼,而不是HTML,有一個簡單的方法來做到這一點?
謝謝!
我想寫類似:如果使用HTML內容,我可以寫內聯嗎?
@(checkCondition ? "<span class='label'>Right!</span>" : "")
但它顯示的源代碼,而不是HTML,有一個簡單的方法來做到這一點?
謝謝!
您可以使用@Html.Raw(mystring)
方法是這樣的:
@(checkCondition ? Html.Raw("<span class='label'>Right!</span>") : Html.Raw(""))
您可以更加簡潔(授予更難讀)本:
@Html.Raw(checkCondition ? "<span class='label'>Right!</span>": string.Empty)
http://stackoverflow.com/questions/ 4091831/how-to-use-ternary-operator-in-razor-specific-on-html-attributes – billyonecan 2013-05-08 14:30:58