Kuttan Sujith
Kuttan Sujith

Reputation: 7979

Turn off default encoding

I have

<%= Html.TextArea("PostContent.Description", Model.PostContent.Description)%>

if I enter

"I am <script>alert()</script> After scrip",


I will get<p>I am &lt;script&gt;alert()&lt;/script&gt; After scrip</p>

by default.

but i don't want this behavior. how can i turn off this default behavior only for this text box

Note that i just want to handle this text box only.

[mvc 2]

Upvotes: 0

Views: 254

Answers (3)

Kuttan Sujith
Kuttan Sujith

Reputation: 7979

i found that it is not possible to avoid default encoding by mvc

Upvotes: 0

Zruty
Zruty

Reputation: 8667

In order to prevent the binder from escaping the HTML characters you can mark the Description property with an [AllowHtml] attribute:

public class ModelPostContent
{
    [AllowHtml]
    public string Description { get; set; }
}

Upvotes: 3

FelisCatus
FelisCatus

Reputation: 5334

Try this:

<textarea name="<%= HtmlHelper.GenerateIdFromName("PostContent.Description") %>"> 
    <%= Model.PostContent.Description %>
</textarea>

Upvotes: 1

Related Questions