How do I encode a string with symbols like ', & @ #' in ASP.Net MVC?
I have tried to use H开发者_开发知识库tml.Encode, but it returns ''', 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.
精彩评论