“<” in a text box in ASP.NET --> how to allow it?

前端 未结 7 2077
粉色の甜心
粉色の甜心 2020-12-01 18:24

I have a textfield which displays a string which contains < and >. The code throws an error because of that. How can I allow the usage of those chars in my textfield?

7条回答
  •  -上瘾入骨i
    2020-12-01 19:04

    Convert them to < and >. In Html, < is converted to < and > is converted to > without it thinking it's part of the markup. So the string will be <Blah>.

    Edit: I forgot, to automatically convert them and escape all HTML characters (so this isn't an issue for other things), in Asp.net you can use Server.HtmlEncode(string) to automatically convert all characters that could cause issues to their HTML equivalent.

提交回复
热议问题