我有一个使用asp.net MVC3 Razor块创建的字符串,如下所示:
@{
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");
});
}
此致 Asif Hameed
答案 0 :(得分:3)
问题在于,在使用@closingMsg
的地方,它会对字符串进行HtmlEncode以确保运行一些有害脚本(如果您放入页面的值来自从用户输入添加的数据库,例如)。
要使其覆盖此内容,您必须使用@Html.Raw(closingMsg)