2011-11-02 86 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