[英]Simple Question: convert a string to an image tag in c# asp.net mvc
I used a generic image handler to handle image 我使用了通用图像处理程序来处理图像
<td width="100px"><%:MyImageHandler.CreateImage(item.PictureId, 100).ToString()%></td>
and the generic handler should return a string like 通用处理程序应返回类似
<img src='/Photo/MyImageHandler.ashx?id=9&size=100'/> <img src ='/ Photo / MyImageHandler.ashx?id = 9&size = 100'/>
I am exhausted to output a string in the form of a image tag 我精疲力竭地以图像标签的形式输出字符串
I tried the string builder and other string constructor and it only return : 我试过了字符串生成器和其他字符串构造器,它只返回:
<img src='/Photo/MyImageHandler.ashx?id=9&size=100'/>
rather than 而不是
<img src='/Photo/MyImageHandler.ashx?id=9&size=100'/> <img src ='/ Photo / MyImageHandler.ashx?id = 9&size = 100'/>
Do you have any suggestions on that? 您对此有何建议? I really need your help.
我真的需要你的帮助。
:
will automatically encode your string which is why your <
is getting turned into a <
:
将自动编码您的字符串,这就是为什么您的<
变成<
You have 2 options 您有2个选择
MvcHtmlString
instead of a string in the method createImage
MvcHtmlString
而不是方法createImage
中的字符串 <%=
instead of <%:
<%=
代替<%:
You would use an MvcHtmlString if you want to return raw HTML from an MVC helper method. 如果要从MVC帮助器方法返回原始HTML,则可以使用MvcHtmlString。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.