[英]Can I write an inline if with HTML content?
我想寫一些類似的東西:
@( 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)
我們也可以這樣做:
@if (checkCondition ) { <text><span class='label'>Right!</span></text> }
text標簽允許你用語法高亮來編寫html!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.