开发者

text/string encoder in javascript

开发者 https://www.devze.com 2023-02-15 10:06 出处:网络
I use ASP.NET MVC in my project. I have used Html.Encode to display some text content and while editing i am finding the text and displaying it in the edit textbox.

I use ASP.NET MVC in my project. I have used Html.Encode to display some text content and while editing i am finding the text and displaying it in the edit textbox.

He开发者_Python百科re is my issue, if the text contains some special character, say , while editing its displayed as <hello> but i wanna display the same as

How can i do this?


You need to Html.Decode it before displaying it to user.

Javascript does not decode html natively


<%= Html.TextAreaFor(model=>model.PropertyName) %>

<textarea>
<%= your_variable %>
</textarea>

same can be done for input.type=text

OR

whatever the way u r doing, there is no need to do Html.Encode when displaying ur data in text box/textarea. Html.Encoding is basically done to avoid injecting script that malicious user tries to inject into ur page. But there is no such issue in case of textarea/input.type=text


The Html.Encode() doesn't support an option to prevent double encoding HTML entities like the PHP htmlentities() function. You'd need to either decode the string first or write a custom HTML Helper that doesn't double encode characters.

0

精彩评论

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

关注公众号