labyrinth
labyrinth

Reputation: 1164

Razor: Expand image as img tag from the string used in p tag

I have a view which uses a list from the model passed to it to populate data. The model for the view is @model IList<NoteData>. The class NoteData contains 2 string variables anchor and data. Values stored in the data field can be of the following form


Detailed Flipflop diagram <img src="http://cpuville.com/images/register_2.jpg"> to use.


I don't want to directly display this value as string but instead show image expanded by the img tag but I am not able to get it working. Thank you in advance for you suggestions

Upvotes: 2

Views: 97

Answers (1)

For this you can use the Html.Raw() method. The method will not encode the string but instead output it as pure html. Something like

@Html.Raw(noteData.data)

should display any image tags. Be wary though that this will output any and all html in the string as pure html, so your site may become vulnerable to script injections if you're using this method.

Upvotes: 3

Related Questions