开发者

Html Encode on a string with symbols

How do I encode a string with symbols like ', & @ #' in ASP.Net MVC?

I have tried to use H开发者_开发知识库tml.Encode, but it returns '&#39', how do I return a string as the user input?

Thanks alot.


If you intend to insert the string into the HTML markup then you need to HTML encode it:

<%= Html.Encode("',&@#'") %>

or if you are using ASP.NET 4.0:

<%: "',&@#'" %>

Doing this will properly encode any characters in the string.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜