2011-11-02 92 views
1

將圖片添加到字符串我使用asp.net MVC3剃刀塊這樣創建的字符串:使用剃刀代碼塊

@{ 
    var closingMsg = "Thank you. Your dispute has been submitted to your Creditor for review. You will receive an email alert on Creditors response."; 

} 

我想它添加圖像,我做了這樣的:

@{ 
    var closingMsg = "Thank you. Your dispute has been submitted to your Creditor for review. You will receive an email alert on Creditors response.'<img src='@Url.Content('~/Content/CR/images/sms-auth.png')' style='float: left; display:block; margin-right:6px;' alt='SMS text verification'/>'"; 

} 

但它不顯示圖像。相反,它將其顯示爲字符串。我該如何改變它?

I am using it in Jquery UI like this: 

    function CloseDisputeDialog() {   
     $("#dispute_form").html("@closingMsg");   
     $("#dispute_form").dialog("addbutton", "Close", function() { 
      $("#dispute_res").val("close"); 
      $("#dispute_form").dialog("close"); 
     }); 
    } 

問候, 阿西夫·哈米德

回答

3

的問題是,在您使用@closingMsg會的HTMLEncode字符串,以確保一些有害的腳本運行(如果你是把到頁面的值是從例如從用戶輸入添加的數據庫)。

爲了得到它來覆蓋這一點,你必須使用@Html.Raw(closingMsg)

+0

我加入它是如何在jQuery中使用。請參閱更新的問題。謝謝 – DotnetSparrow

+0

DotnetSparrow - 仍然,用@ Html.Raw(closingMsg)替換@closingMsg應該可以工作。所以把$(「#dispute_form」)。html(「@ Html.Raw(closingMsg)」); –

+0

我用過,但它沒有顯示圖像。可能是我需要給相對路徑? – DotnetSparrow