This is contrived, but its basically what I'm doing. I have an a @helper like so:
@helper MyImage(int i) {
String s = "<img src='{0}' />";
String theImage = "";
switch(i) {
case 0: theImage = "test1.png"; break;
case 1: theImage = "test2.png"; break;
default: theImage = "error.png"; break;
}
String r = String.Format(s, theImage);
@(r)
}
The output I get on the web page is of course the actual string:
<img src='test1.png' />
instead of the image. Is there a way to disable it from encoding it that way?
You could use @Html.Raw(r)
rather than just @(r)
.
http://msdn.microsoft.com/en-us/library/system.web.mvc.mvchtmlstring.aspx
@(new MvcHtmlString(r))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With