开发者

Html Encode on a string with symbols

开发者 https://www.devze.com 2023-01-03 20:27 出处:网络
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?

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

精彩评论

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

关注公众号