简体   繁体   English

一个简单的问题:将字符串转换为c#asp.net mvc中的图像标签

[英]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 : 我试过了字符串生成器和其他字符串构造器,它只返回:

&lt;img src='/Photo/MyImageHandler.ashx?id=9&amp;size=100'/&gt;

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 &lt; :将自动编码您的字符串,这就是为什么您的<变成&lt;

You have 2 options 您有2个选择

  1. return a MvcHtmlString instead of a string in the method createImage 返回MvcHtmlString而不是方法createImage中的字符串
  2. use <%= 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM