nimi
nimi

Reputation: 5507

text/string encoder in javascript

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.

Here 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?

Upvotes: 0

Views: 329

Answers (3)

ASP.NET MVC Tips
ASP.NET MVC Tips

Reputation: 331

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.

Upvotes: 0

Praveen Prasad
Praveen Prasad

Reputation: 32137

<%= 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

Upvotes: 0

moe
moe

Reputation: 29774

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

Javascript does not decode html natively

Upvotes: 1

Related Questions