1

I have a string created using asp.net MVC3 Razor block like this:

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

}

I want to add an image in it which i did like this:

@{
    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'/>'";

}

But It doesn't show image. Rather, It shows it as string. how can I change it ?

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");   
        });
    }

Regards, Asif Hameed

1 Answer 1

3

The problem is that where you use @closingMsg it will HtmlEncode the string to make sure some harmful scripts are run (if the value you are putting into the page are from the database that is added from user input for example).

To get it to override this, you have to use @Html.Raw(closingMsg)

Sign up to request clarification or add additional context in comments.

4 Comments

I have added how it is used in Jquery. Please see updated question. thanks
DotnetSparrow - Still, replace @closingMsg with @Html.Raw(closingMsg) should work. So put $("#dispute_form").html("@Html.Raw(closingMsg)");
I used that but It doesn't show the image. may be I need to give relative path ?
Does it show a image that is not found on the page, or does it spell out the html code like <img.... directly on the page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.